2 // Author: Sergey Chaban (serge@wildwestsoftware.com)
11 internal class StringHelper
: StringHelperBase
{
13 private static readonly string idChars
= "_$@?";
17 /// <param name="host"></param>
18 public StringHelper (ILTokenizer host
) : base (host
)
25 /// <returns></returns>
26 public override bool Start (char ch
)
30 if (Char
.IsLetter (ch
) || idChars
.IndexOf (ch
) != -1) {
32 } else if (ch
== '\'') {
33 mode
= Token
.SQSTRING
;
34 } else if (ch
== '"') {
38 return (mode
!= Token
.UNKNOWN
);
42 private static bool IsIdChar (int c
)
45 return (Char
.IsLetterOrDigit(ch
) || idChars
.IndexOf (ch
) != -1);
50 /// <returns></returns>
51 public override string Build ()
53 if (mode
== Token
.UNKNOWN
) return String
.Empty
;
56 ILReader reader
= host
.Reader
;
58 StringBuilder idsb
= new StringBuilder ();
59 if (mode
== Token
.SQSTRING
|| mode
== Token
.QSTRING
) {
60 int term
= (mode
== Token
.SQSTRING
) ? '\'' : '"';
61 reader
.Read (); // skip quote
62 for (ch
= reader
.Read (); ch
!= -1; ch
= reader
.Read ()) {
71 * Long string can be broken across multiple lines
72 * by using '\' as the last char in line.
73 * Any white space chars between '\' and the first
74 * char on the next line are ignored.
77 reader
.SkipWhitespace ();
81 int escaped
= Escape (ch
);
90 idsb
.Append((char)ch
);
93 while ((ch
= reader
.Read ()) != -1) {
95 idsb
.Append ((char) ch
);
102 return idsb
.ToString ();
110 /// <param name="ch"></param>
111 /// <returns></returns>
112 public static int Escape (int ch
)
116 if (ch
>= '0' && ch
<='7') {
119 int id
= "abfnrtv\"'\\".IndexOf ((char)ch
);
121 res
= "\a\b\f\n\r\t\v\"'\\" [id
];