Quoting rules



  • Quoting from the android string resource format description:

    Escaping apostrophes and quotes

    If you have an apostrophe or a quote in your string, you must either escape it or enclose the whole string in the other type of enclosing quotes. For example, here are some stings that do and don't work:

    <string name="good_example">"This'll work"</string>
    <string name="good_example_2">This\'ll also work</string>
    <string name="bad_example">This doesn't work</string>
    <string name="bad_example_2">XML encodings don&apos;t work</string>
    

    And when I tried it

    <string name="weird_example">This "seem'd" to work</string>
    

    Now Why The Fuck does it need escaping. And so convoluted one in particular.



  • So TRWTF is that you can't figure it out?



  •  

    you must either escape it or enclose the
    whole string in the other type of enclosing quotes.

     TRWTF is you.



  • @Mole said:

     

    you must either escape it or enclose the
    whole string in the other type of enclosing quotes.

     TRWTF is you.

     

    He accidentally didn't the [b]whole string[/b]



  • @Lorne Kates said:

    @Mole said:
    you must either escape it or enclose the
    whole string in the other type of enclosing quotes.

     TRWTF is you.

    He accidentally didn't the whole string
     

    Apparently you don't need to the whole string, just the word containing the apostrophe.

     



  • @Bulb said:

    Now Why The Fuck does it need escaping. And so convoluted one in particular.

    The escaping would sound reasonable to me. If it wasn't an XML file.



  • @Bulb said:

    <string name="bad_example_2">XML encodings don&apos;t work</string>

    TRWTF.

    I assume that some back-end process would turn this into Java code, but seeing as this is supposedly XML...



  • @boomzilla said:

    So TRWTF is that you can't figure it out?

    I can figure out how to write it just fine. I just wonder why it needs any quoting rules when the characters don't have any special meaning in XML and the quoting rules don't match the intermediate format (Java) either.



  • @MiffTheFox said:

    @Bulb said:
    <string name="bad_example_2">XML encodings don&apos;t work</string>

    TRWTF.

    I assume that some back-end process would turn this into Java code, but seeing as this is supposedly XML...

    Yes, a conversion tool turns it into Java code and compiles it. However, Java uses only double-quotes for quoting strings, so the whole business with single quotes just means that the conversion tool has to parse it and escape it differently for Java anyway.



  • @Bulb said:

    @boomzilla said:
    So TRWTF is that you can't figure it out?

    I can figure out how to write it just fine. I just wonder why it needs any quoting rules when the characters don't have any special meaning in XML and the quoting rules don't match the intermediate format (Java) either.

    Ah. Then another WTF is why everybody thinks the escapes are for the XML. TRWTF may be that the Android internals just want you to do the escaping so it doesn't have to. It's hard to say without knowing more about what, exactly, they're doing. Does the IDE have an editor that handles that for you? Or do you have to write the XML by hand?

    What actually happens when you put in an invalidly escaped quote? Compiler error? Malformed string displayed?



  • @Bulb said:

    <string name="bad_example_2">XML encodings in an XML resource file don&apos;t work</string>
     

    i almost lol'd.



  • @boomzilla said:

    Ah. Then another WTF is why everybody thinks the escapes are for the XML. TRWTF may be that the Android internals just want you to do the escaping so it doesn't have to. It's hard to say without knowing more about what, exactly, they're doing.

    The escapes clearly are not for the XML. But whatever tool needs them is pretty convoluted and makes no sense, since the quotes don't have any special meaning. They are just stripped as long as they are paired.
    @boomzilla said:
    Does the IDE have an editor that handles that for you? Or do you have to write the XML by hand?

    It does have an IDE. Eclipse. But can you imagine asking the translators (who are usually anything but computer savvy) to install that? Plus it only works if you have the whole project—and one can't just give it to external translation agency. Besides the format is simple, but useless when it comes to translation. There are separate files, each relating identifiers to messages in one language. So when you change the English text, you may easily miss you need to change the translations too. So what I actually did was write a python script to fill the keys to a translation catalogue and pull the translations back.
    @boomzilla said:
    What actually happens when you put in an invalidly escaped quote? Compiler error? Malformed string displayed?

    If there is an odd unescaped quote or apostrophe, the conversion errors out. Any even number of unescaped quotes or apostrophes seems to be simply discarded (between them, the other quotes are kept).



  • @Bulb said:


    Escaping apostrophes and quotes

    If you have an apostrophe or a quote in your string, you must either escape it or enclose the whole string in the other type of enclosing quotes ...

    What is this „other“ type they speak of?

    @Bulb said:

    And when I tried it

    <string name="weird_example">This "seem'd" to work</string>

    See, I thought that you were asking how you'd quote the string «This "seem'd" to work», since neither type of quotation mark is now available to you. I am not sure whether I want to know what sort of ass-backwards system Google have set up that puts this back on the developer to sort out, when there's no reason for it to ever be an issue in the frist place. It's pretty messed up.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.