本文整理汇总了C#中MongoDB.Bson.IO.JsonBuffer.GetSubstring方法的典型用法代码示例。如果您正苦于以下问题:C# JsonBuffer.GetSubstring方法的具体用法?C# JsonBuffer.GetSubstring怎么用?C# JsonBuffer.GetSubstring使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoDB.Bson.IO.JsonBuffer
的用法示例。
在下文中一共展示了JsonBuffer.GetSubstring方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetNumberToken
//.........这里部分代码省略.........
{
state = NumberState.Invalid;
}
break;
case NumberState.SawExponentDigits:
switch (c)
{
case ',':
case '}':
case ']':
case ')':
case -1:
state = NumberState.Done;
break;
default:
if (char.IsDigit((char)c))
{
state = NumberState.SawExponentDigits;
}
else if (char.IsWhiteSpace((char)c))
{
state = NumberState.Done;
}
else
{
state = NumberState.Invalid;
}
break;
}
break;
case NumberState.SawMinusI:
var sawMinusInfinity = true;
var nfinity = new char[] { 'n', 'f', 'i', 'n', 'i', 't', 'y' };
for (var i = 0; i < nfinity.Length; i++)
{
if (c != nfinity[i])
{
sawMinusInfinity = false;
break;
}
c = buffer.Read();
}
if (sawMinusInfinity)
{
type = JsonTokenType.Double;
switch (c)
{
case ',':
case '}':
case ']':
case ')':
case -1:
state = NumberState.Done;
break;
default:
if (char.IsWhiteSpace((char)c))
{
state = NumberState.Done;
}
else
{
state = NumberState.Invalid;
}
break;
}
}
else
{
state = NumberState.Invalid;
}
break;
}
switch (state)
{
case NumberState.Done:
buffer.UnRead(c);
var lexeme = buffer.GetSubstring(start, buffer.Position - start);
if (type == JsonTokenType.Double)
{
var value = XmlConvert.ToDouble(lexeme);
return new DoubleJsonToken(lexeme, value);
}
else
{
var value = XmlConvert.ToInt64(lexeme);
if (value < int.MinValue || value > int.MaxValue)
{
return new Int64JsonToken(lexeme, value);
}
else
{
return new Int32JsonToken(lexeme, (int)value);
}
}
case NumberState.Invalid:
throw new FileFormatException(FormatMessage("Invalid JSON number", buffer, start));
}
}
}
示例2: GetStringToken
private static JsonToken GetStringToken(JsonBuffer buffer, char quoteCharacter)
{
// opening quote has already been read
var start = buffer.Position - 1;
var sb = new StringBuilder();
while (true)
{
var c = buffer.Read();
switch (c)
{
case '\\':
c = buffer.Read();
switch (c)
{
case '\'': sb.Append('\''); break;
case '"': sb.Append('"'); break;
case '\\': sb.Append('\\'); break;
case '/': sb.Append('/'); break;
case 'b': sb.Append('\b'); break;
case 'f': sb.Append('\f'); break;
case 'n': sb.Append('\n'); break;
case 'r': sb.Append('\r'); break;
case 't': sb.Append('\t'); break;
case 'u':
var u1 = buffer.Read();
var u2 = buffer.Read();
var u3 = buffer.Read();
var u4 = buffer.Read();
if (u4 != -1)
{
var hex = new string(new char[] { (char)u1, (char)u2, (char)u3, (char)u4 });
var n = Convert.ToInt32(hex, 16);
sb.Append((char)n);
}
break;
default:
if (c != -1)
{
var message = string.Format("Invalid escape sequence in JSON string '\\{0}'.", (char)c);
throw new FileFormatException(message);
}
break;
}
break;
default:
if (c == quoteCharacter)
{
var lexeme = buffer.GetSubstring(start, buffer.Position - start);
return new StringJsonToken(JsonTokenType.String, lexeme, sb.ToString());
}
if (c != -1)
{
sb.Append((char)c);
}
break;
}
if (c == -1)
{
throw new FileFormatException(FormatMessage("End of file in JSON string.", buffer, start));
}
}
}
示例3: GetUnquotedStringToken
private static JsonToken GetUnquotedStringToken(JsonBuffer buffer)
{
// opening letter or $ has already been read
var start = buffer.Position - 1;
var c = buffer.Read();
while (c == '$' || c == '_' || char.IsLetterOrDigit((char)c))
{
c = buffer.Read();
}
buffer.UnRead(c);
var lexeme = buffer.GetSubstring(start, buffer.Position - start);
return new StringJsonToken(JsonTokenType.UnquotedString, lexeme, lexeme);
}
示例4: GetRegularExpressionToken
private static JsonToken GetRegularExpressionToken(JsonBuffer buffer)
{
// opening slash has already been read
var start = buffer.Position - 1;
var state = RegularExpressionState.InPattern;
while (true)
{
var c = buffer.Read();
switch (state)
{
case RegularExpressionState.InPattern:
switch (c)
{
case '/': state = RegularExpressionState.InOptions; break;
case '\\': state = RegularExpressionState.InEscapeSequence; break;
default: state = RegularExpressionState.InPattern; break;
}
break;
case RegularExpressionState.InEscapeSequence:
state = RegularExpressionState.InPattern;
break;
case RegularExpressionState.InOptions:
switch (c)
{
case 'i':
case 'm':
case 'x':
case 's':
state = RegularExpressionState.InOptions;
break;
case ',':
case '}':
case ']':
case ')':
case -1:
state = RegularExpressionState.Done;
break;
default:
if (char.IsWhiteSpace((char)c))
{
state = RegularExpressionState.Done;
}
else
{
state = RegularExpressionState.Invalid;
}
break;
}
break;
}
switch (state)
{
case RegularExpressionState.Done:
buffer.UnRead(c);
var lexeme = buffer.GetSubstring(start, buffer.Position - start);
var regex = new BsonRegularExpression(lexeme);
return new RegularExpressionJsonToken(lexeme, regex);
case RegularExpressionState.Invalid:
throw new FileFormatException(FormatMessage("Invalid JSON regular expression", buffer, start));
}
}
}