/// <summary> /// Read in a sequence of characters that are all valid in JSON numbers. Does /// not do a complete regex check to validate that this is actually a number. /// </summary> private async ValueTask <string> ReadJsonNumericCharsAsync(CancellationToken cancellationToken) { var strbld = new StringBuilder(); while (true) { //TODO: workaround for primitive types with TJsonProtocol, think - how to rewrite into more easy form without exceptions try { var ch = await Reader.PeekAsync(cancellationToken); if (!TJSONProtocolHelper.IsJsonNumeric(ch)) { break; } var c = (char)await Reader.ReadAsync(cancellationToken); strbld.Append(c); } catch (TTransportException) { break; } } return(strbld.ToString()); }
public void IsJsonNumeric_Test() { // input/output var correctJsonNumeric = "+-.0123456789Ee"; var incorrectJsonNumeric = "AaBcDd/*\\"; var sets = correctJsonNumeric.Select(ch => new Tuple <byte, bool>((byte)ch, true)).ToList(); sets.AddRange(incorrectJsonNumeric.Select(ch => new Tuple <byte, bool>((byte)ch, false))); foreach (var t in sets) { Assert.IsTrue(TJSONProtocolHelper.IsJsonNumeric(t.Item1) == t.Item2, $"Wrong mapping of Char {t.Item1} to bool: {t.Item2}"); } }