Parsing a Java Properties file in Objective-C for iPhone

后端 未结 6 952
情话喂你
情话喂你 2021-01-18 19:09

I\'m looking for a way in the iPhone SDK to read in a Properties file (not the XML flavor) for example this one:

# a comment
! a comment

a = a string
b = a          


        
6条回答
  •  温柔的废话
    2021-01-18 19:36

    It's a perfectly simple parsing problem. Read a line. Ignore if comment. Check for continuation, and read/append continuation lines as needed. Look for the "=". Make the left side of the "=" (after trimming white space) the key. Either parse the right side yourself or put it into an NSString and use stringWithFormat on it to "reduce" any escapes to pure character form. Return key and reduced right side.

    (But refreshing my memory on the properties file format reminds me that:

    The key contains all of the characters in the line starting with the first non-white space character and up to, but not including, the first unescaped '=', ':', or white space character other than a line terminator. All of these key termination characters may be included in the key by escaping them with a preceding backslash character;

    So a little scanning of the line is required to separate the key from the rest. Nothing particularly difficult, though.)

提交回复
热议问题