LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  Constructing unicode literal

    Employee
    Posted 01-27-2012 07:32

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: dvs79

    Hello!

    I need to construct unicode value, using a string variable containing hexadecimal value of a unicode symbol. How can I do it?

    I. e., I have code:string="0420". I need to get u"\u0420" for printing cyrillic letter "Щ". I've constructed a new string "u"\u0420"", but it's still considered by BRAINscript just as a string and doesn't produce expected cyrillic letter.
    How can I do it?


  • 2.  RE: Constructing unicode literal

    Employee
    Posted 01-27-2012 09:02

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: timonk

    Dmitry,

    Here is a very simple graph example on how you can declare a unicode escape string.

    The code in the filter is just this:
    unistring = u"\u0429"
    emit unistring as "unicoded"

    The output of the filter is a щ character.

    Looking at your post I think you have extra quotes, unless thats just from your posting.

    Is this what you needed?

    Regards,
    Timon Koufopoulos
    MDS Lavastorm Support.
    Attachments:
    cyrillic_unicode.brg


  • 3.  RE: Constructing unicode literal

    Employee
    Posted 01-27-2012 11:09

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: dvs79

    Hi Timon!

    Not exactly. Have a look at the attached example. I want to add the code (e.g.0420) as a variable value. But I can only create a string that "imitates" a real unicode escape string, but doesn't work as needed.
    Attachments:
    unicode_ex.brg


  • 4.  RE: Constructing unicode literal

    Employee
    Posted 01-27-2012 15:02

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: timonk

    Dmitry,

    Ah, I see. Unfortunately I don't think this will work for you, the way you want it.

    One option, which I will see about getting an example of, is to use a Python Filter, instead of a standard filter. It should only need a few small lines of code to work. But there is not a direct brainscript way to do what you are attempting.

    Regards,
    Timon


  • 5.  RE: Constructing unicode literal

    Employee
    Posted 01-31-2012 14:18

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: matt

    You can do this:

    emit code, unescape(u"\\u"+code) as ucd_symb

    The trick in this is the unescape function, which seems to be missing from the brainscript documentation.

    However, an extensive write-up is contained in the Release Notes for the 4.1.2 release. (The release notes can be found in the file "BRAIN Releases Notes.pdf" for 4.1.x installs and the "LAE (BRAIN) Releases Notes to 4.1.8.pdf" for 4.5.x installs.

    I have filed a bug against the online documentation to include an entry for the unescape function.

    Matt


  • 6.  RE: Constructing unicode literal

    Employee
    Posted 02-01-2012 05:17

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: dvs79

    Matt, thanks a lot, what I needed!