public string ToString(char split) { if (size == 0) { return("[]"); } Entry[] values = this.valuesTable; StrBuilder buffer = new StrBuilder(32); buffer.Append('['); for (int i = 0; i < size; i++) { object key = values[i].key; object value = values[i].value; buffer.Append(key == this ? "(this Map)" : key); buffer.Append('='); buffer.Append(value == this ? "(this Map)" : value); if (i < size - 1) { buffer.Append(split).Append(' '); } } buffer.Append(']'); return(buffer.ToString()); }
public static string Escape(string raw) { if (IsEmpty(raw)) { return(""); } int length = raw.Length(); int i = 0; StrBuilder sbr = new StrBuilder(raw.Length() / 2); while (i < length) { char c = raw.CharAt(i++); if (CharUtils.IsLetterOrDigit(c) || CharUtils.IsEscapeExempt(c)) { sbr.Append(c); } else { int i1 = raw.CharAt(i - 1); string escape = CharUtils.ToHex(i1); sbr.Append('%'); if (escape.Length > 2) { sbr.Append('u'); } sbr.Append(escape.ToUpper()); } } return(sbr.ToString()); }
public static string Replace(string message, string oldString, string newString) { if (message == null) { return(null); } if (newString == null) { return(message); } int i = 0; if ((i = message.IndexOf(oldString, i)) >= 0) { char[] string2 = message.ToCharArray(); char[] newString2 = newString.ToCharArray(); int oLength = oldString.Length(); StrBuilder buf = new StrBuilder(string2.Length); buf.Append(string2, 0, i).Append(newString2); i += oLength; int j; for (j = i; (i = message.IndexOf(oldString, i)) > 0; j = i) { buf.Append(string2, j, i - j).Append(newString2); i += oLength; } buf.Append(string2, j, string2.Length - j); return(buf.ToString()); } else { return(message); } }
private void InitBuild() { if (!_init_buffer && _buffer == null) { _buffer = new StrBuilder(capacity); _init_buffer = true; } }
public static string FormatEscape(string cs, string indent) { string text = cs.ToString(); if (text.IndexOf('\n') != -1) { if (text.Length == 1) { return(Quote("\\n")); } StrBuilder sbr = new StrBuilder(); sbr.Append("|"); string[] lines = Split(text, '\n'); for (int i = 0; i < lines.Length; i++) { string line = lines[i]; sbr.Append("\n" + indent + line); } if (text[text.Length - 1] == '\n') { sbr.Append("\n" + indent); } return(sbr.ToString()); } else if ("".Equals(text)) { return(Quote(text)); } else { const string indicators = ":[]{},\"'|*&"; bool quoteIt = false; foreach (char c in indicators.ToCharArray()) { if (text.IndexOf(c) != -1) { quoteIt = true; break; } } if (text.Trim().Length != text.Length) { quoteIt = true; } if (MathUtils.IsNumber(text)) { quoteIt = true; } if (quoteIt) { text = Escape(text); text = Quote(text); } return(text); } }
public static string GetRandString(int size) { StrBuilder str = new StrBuilder(size); char ch; for (int i = 0; i < size; i++) { ch = Convert.ToChar(Convert.ToInt32(MathUtils.Floor(MathUtils.Random() * 26 + 65))); str.Append(ch); } return(str.ToString()); }
public string EncryptBytes(sbyte[] buffer) { Md5Init(); Md5Update(buffer, buffer.Length); Md5Final(); StrBuilder buf = new StrBuilder(); for (int i = 0; i < 16; i++) { buf.Append(CharUtils.ToHex(digest[i])); } return(buf.ToString()); }
public string ReadUTF() { CheckAvailable(2); int utfLength = ReadShort() & 0xffff; CheckAvailable(utfLength); int goalPosition = Position() + utfLength; StrBuilder strings = new StrBuilder(utfLength); while (Position() < goalPosition) { int a = ReadByte() & 0xff; if ((a & 0x80) == 0) { strings.Append((char)a); } else { int b = ReadByte() & 0xff; if ((b & 0xc0) != 0x80) { throw new LSysException(StringExtensions.ValueOf(b)); } if ((a & 0xe0) == 0xc0) { char ch = (char)(((a & 0x1f) << 6) | (b & 0x3f)); strings.Append(ch); } else if ((a & 0xf0) == 0xe0) { int c = ReadByte() & 0xff; if ((c & 0xc0) != 0x80) { throw new LSysException(StringExtensions.ValueOf(c)); } char ch = (char)(((a & 0x0f) << 12) | ((b & 0x3f) << 6) | (c & 0x3f)); strings.Append(ch); } else { throw new LSysException("null"); } } } return(strings.ToString()); }
public static string Format(string format, params object[] o) { if (CollectionUtils.IsEmpty(o)) { return(""); } StrBuilder b = new StrBuilder(); int p = 0; for (; ;) { int i = format.IndexOf('{', p); if (i == -1) { break; } int idx = format.IndexOf('}', i + 1); if (idx == -1) { break; } if (p != i) { b.Append(format.Substring(p, i)); } string nstr = format.Substring(i + 1, idx); try { int n = Integer.ParseInt(nstr); if (n >= 0 && n < o.Length) { b.Append(o[n]); } else { b.Append('{').Append(nstr).Append('}'); } } catch (java.lang.Exception) { b.Append('{').Append(nstr).Append('}'); } p = idx + 1; } b.Append(format.Substring(p)); return(b.ToString()); }
private static void FormatTime(StrBuilder tag, string pfx, int dgt, long val) { tag.Append(pfx); if (dgt > 1) { int pad = (dgt - 1); for (long i = val; i > 9 && pad > 0; i /= 10) { pad--; } for (int j = 0; j < pad; j++) { tag.Append('0'); } } tag.Append(val); }
public static string FormatSeconds(int secondsTotal, StrBuilder output) { int second = 60; int minutes = secondsTotal / second; int seconds = secondsTotal % second; output.Append(minutes); output.Append(':'); if (seconds < 10) { output.Append('0'); } output.Append(seconds); return(output.ToString()); }
public static string FormatMillis(long val) { StrBuilder sbr = new StrBuilder(20); string sgn = ""; if (val < 0) { sgn = "-"; } val = MathUtils.Abs(val); FormatTime(sbr, sgn, 0, (val / 3600000)); val %= 3600000; FormatTime(sbr, ":", 2, (val / 60000)); val %= 60000; FormatTime(sbr, ":", 2, (val / 1000)); return(sbr.ToString()); }
public static string Join(char flag, params string[] o) { if (CollectionUtils.IsEmpty(o)) { return(""); } StrBuilder sbr = new StrBuilder(); int size = o.Length; for (int i = 0; i < size; i++) { sbr.Append(o[i]); if (i < size - 1) { sbr.Append(flag); } } return(sbr.ToString()); }
public string ToString(char split) { if (length == 0) { return("[]"); } sbyte[] bytebuffer = this.bytebuffer; StrBuilder buffer = new StrBuilder(CollectionUtils.INITIAL_CAPACITY); buffer.Append('['); buffer.Append(StringUtils.ToHex(bytebuffer[0])); for (int i = 1; i < length; i++) { buffer.Append(split); buffer.Append(StringUtils.ToHex(bytebuffer[i])); } buffer.Append(']'); return(buffer.ToString()); }
public string ToString(char split) { if (length == 0) { return("[]"); } bool[] items = this.items; StrBuilder buffer = new StrBuilder(32); buffer.Append('['); buffer.Append(items[0]); for (int i = 1; i < length; i++) { buffer.Append(split); buffer.Append(items[i]); } buffer.Append(']'); return(buffer.ToString()); }
public StringKeyValue Kv(string key, object[] values) { if (key == null && values == null) { return(this); } int size = values.Length; StrBuilder sbr = new StrBuilder(size + 32); sbr.Append('{'); for (int i = 0; i < size; i++) { sbr.Append(values[i]); if (i < size - 1) { sbr.Append(','); } } sbr.Append('}'); return(Kv(key, sbr.ToString())); }
public override string ToString() { LIterator <E> it = Iterator(); if (!it.HasNext()) { return("[]"); } StrBuilder sbr = new StrBuilder(); sbr.Append('['); for (it = _map.GetKeys(); it.HasNext();) { E e = it.Next(); sbr.Append((object)e == (object)this ? "(this ObjectSet)" : e.ToString()); if (!it.HasNext()) { return(sbr.Append(']').ToString()); } sbr.Append(',').Append(' '); } return(sbr.ToString()); }
public static string FormatCRLF(string cs) { if (IsEmpty(cs)) { return(LSystem.EMPTY); } string src = cs.ToString(); int pos = src.IndexOf("\r", StringComparison.Ordinal); if (pos != -1) { int len = src.Length; StrBuilder buffer = new StrBuilder(); int lastPos = 0; while (pos != -1) { buffer.Append(src, lastPos, pos); if (pos == len - 1 || src[pos + 1] != '\n') { buffer.Append('\n'); } lastPos = pos + 1; if (lastPos >= len) { break; } pos = src.IndexOf("\r", lastPos, StringComparison.Ordinal); } if (lastPos < len) { buffer.Append(src, lastPos, len); } src = buffer.ToString(); } return(src); }