Example #1
0
 /// <summary>
 /// This will add a <c>String</c> to the end of the buffer.
 /// The buffer will not overflow with repeated uses of the
 /// <c>append</c>, it uses an <c>ensureCapacity</c>
 /// method which will allow the buffer to dynamically grow in
 /// size to accomodate large <c>String</c> objects.
 /// </summary>
 /// <param name="str">
 /// the <c>String</c> to be appended to this
 /// </param>
 public void Append(String str) {
    EnsureCapacity(count+ str.Length());
    str.getChars(0,str.Length(),buf,count);
    count += str.Length();
 }
Example #2
0
 /**
  * Used to convert raw characters to their escaped version
  * when these raw version cannot be used as part of an ASCII
  * string literal.
  */
 static string add_escapes(String str)
 {
     StringBuilder retval = new StringBuilder();
     char ch;
     for (int i = 0; i < str.Length(); i++)
     {
         switch (str[i])
         {
             case '\0':
                 continue;
             case '\b':
                 retval.Append("\\b");
                 continue;
             case '\t':
                 retval.Append("\\t");
                 continue;
             case '\n':
                 retval.Append("\\n");
                 continue;
             case '\f':
                 retval.Append("\\f");
                 continue;
             case '\r':
                 retval.Append("\\r");
                 continue;
             case '\"':
                 retval.Append("\\\"");
                 continue;
             case '\'':
                 retval.Append("\\\'");
                 continue;
             case '\\':
                 retval.Append("\\\\");
                 continue;
             default:
                 if ((ch = str[i]) < 0x20 || ch > 0x7e)
                 {
                     String s = "0000" + Integer.toString(ch, 16);
                     retval.Append("\\u" + s.Substring(s.Length() - 4, s.Length()));
                 }
                 else
                 {
                     retval.Append(ch);
                 }
                 continue;
         }
     }
     return retval.toString();
 }