public static string PercentDecode(this string me) { Text.Builder result = null; if (me.NotNull()) { Generic.IEnumerator <char> enumerator = me.GetEnumerator(); while (enumerator.MoveNext()) { if (enumerator.Current == '%') { char[] characters = new char[] { enumerator.Next(), enumerator.Next() }; byte value; if (byte.TryParse(new string(characters), System.Globalization.NumberStyles.HexNumber, System.Globalization.NumberFormatInfo.InvariantInfo, out value)) { result += System.Text.Encoding.ASCII.GetChars(new byte[] { value }); } else { result += "%" + characters; } } else { result += enumerator.Current; } } } return(result); }
public static async Tasks.Task <string> ReadUpTo(this ITextReader me, Func <char, bool> predicate) { Text.Builder result = await me.Empty ? null : ""; char? next; while ((next = await me.Read(predicate.Negate())).HasValue) { result += next.Value; } return(result); }
public static ICharacterOutDevice Open(Action <string> done) { Text.Builder output = null; var result = new CharacterOutDevice(content => { output += content; }); result.OnClose += () => { done(output); }; return(result); }
public override int setupRequest(Common.FastRand rng, CatRankSchema.SearchResultList.Builder request) { int count = rng.nextLessThan(1000); int goodCount = 0; StructList.Builder <CatRankSchema.SearchResult.Builder> list = request.InitResults(count); for (int i = 0; i < list.Length; ++i) { CatRankSchema.SearchResult.Builder result = list.Get(i); result.SetScore(1000.0 - (double)i); int urlSize = rng.nextLessThan(100); int urlPrefixLength = URL_PREFIX.Length; Text.Builder url = result.InitUrl(urlSize + urlPrefixLength); java.nio.ByteBuffer bytes = url.asByteBuffer(); bytes.put(URL_PREFIX.asByteBuffer()); for (int j = 0; j < urlSize; j++) { bytes.put(unchecked ((byte)(97 + rng.nextLessThan(26)))); } bool isCat = rng.nextLessThan(8) == 0; bool isDog = rng.nextLessThan(8) == 0; if (isCat && !isDog) { goodCount += 1; } System.Text.StringBuilder snippet = new System.Text.StringBuilder(" "); int prefix = rng.nextLessThan(20); for (int j = 0; j < prefix; ++j) { snippet.Append(Common.WORDS[rng.nextLessThan(Common.WORDS.Length)]); } if (isCat) { snippet.Append("cat "); } if (isDog) { snippet.Append("dog "); } int suffix = rng.nextLessThan(20); for (int j = 0; j < suffix; ++j) { snippet.Append(Common.WORDS[rng.nextLessThan(Common.WORDS.Length)]); } result.SetSnippet(snippet.ToString()); } return(goodCount); }
public static string PercentEncode(this string me, params char[] characters) { if (characters.Empty()) { characters = new char[] { ' ', '"', '!', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '/', ':', ';', '=', '?', '@', '[', ']' } } ; Text.Builder result = null; if (me.NotNull()) { foreach (char c in me) { if (characters.Contains(c)) { result += "%" + System.Text.Encoding.ASCII.GetBytes(new char[] { c }).First().ToString("X2"); } else { result += c; } } } return(result); }
void Read(char character) { this.content += character; }