本文整理汇总了C#中MongoDB.Bson.IO.JsonBuffer类的典型用法代码示例。如果您正苦于以下问题:C# JsonBuffer类的具体用法?C# JsonBuffer怎么用?C# JsonBuffer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JsonBuffer类属于MongoDB.Bson.IO命名空间,在下文中一共展示了JsonBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetNextToken
/// <summary>
/// Gets the next JsonToken from a JsonBuffer.
/// </summary>
/// <param name="buffer">The buffer.</param>
/// <returns>The next token.</returns>
public static JsonToken GetNextToken(
JsonBuffer buffer
) {
// skip leading whitespace
var c = buffer.Read();
while (c != -1 && char.IsWhiteSpace((char) c)) {
c = buffer.Read();
}
if (c == -1) {
return new JsonToken(JsonTokenType.EndOfFile, "<eof>");
}
// leading character determines token type
switch (c) {
case '{': return new JsonToken(JsonTokenType.BeginObject, "{");
case '}': return new JsonToken(JsonTokenType.EndObject, "}");
case '[': return new JsonToken(JsonTokenType.BeginArray, "[");
case ']': return new JsonToken(JsonTokenType.EndArray, "]");
case ':': return new JsonToken(JsonTokenType.Colon, ":");
case ',': return new JsonToken(JsonTokenType.Comma, ",");
case '"': return GetStringToken(buffer);
case '/': return GetRegularExpressionToken(buffer);
default:
if (c == '-' || char.IsDigit((char) c)) {
return GetNumberToken(buffer, c);
} else if (c == '$' || char.IsLetter((char) c)) {
return GetUnquotedStringToken(buffer);
} else {
buffer.UnRead(c);
throw new FileFormatException(FormatMessage("Invalid JSON input", buffer, buffer.Position));
}
}
}
示例2: JsonReader
public JsonReader(
JsonBuffer buffer
)
{
this.buffer = buffer;
this.context = new JsonReaderContext(null, ContextType.TopLevel);
}
示例3: JsonReader
// constructors
/// <summary>
/// Initializes a new instance of the JsonReader class.
/// </summary>
/// <param name="buffer">The buffer.</param>
/// <param name="settings">The reader settings.</param>
public JsonReader(JsonBuffer buffer, JsonReaderSettings settings)
: base(settings)
{
_buffer = buffer;
_jsonReaderSettings = settings; // already frozen by base class
_context = new JsonReaderContext(null, ContextType.TopLevel);
}
示例4: JsonReader
/// <summary>
/// Initializes a new instance of the JsonReader class.
/// </summary>
/// <param name="buffer">The buffer.</param>
/// <param name="settings">The reader settings.</param>
public JsonReader(
JsonBuffer buffer,
JsonReaderSettings settings
) {
this.buffer = buffer;
this.settings = settings.Freeze();
this.context = new JsonReaderContext(null, ContextType.TopLevel);
}
示例5: TestNameSeparator
public void TestNameSeparator() {
var json = "\t :x";
var buffer = new JsonBuffer(json);
var token = JsonScanner.GetNextToken(buffer);
Assert.AreEqual(JsonTokenType.Colon, token.Type);
Assert.AreEqual(":", token.Lexeme);
Assert.AreEqual('x', buffer.Read());
}
示例6: TestEndArray
public void TestEndArray() {
var json = "\t ]x";
var buffer = new JsonBuffer(json);
var token = JsonScanner.GetNextToken(buffer);
Assert.AreEqual(JsonTokenType.EndArray, token.Type);
Assert.AreEqual("]", token.Lexeme);
Assert.AreEqual('x', buffer.Read());
}
示例7: TestBeginObject
public void TestBeginObject() {
var json = "\t {x";
var buffer = new JsonBuffer(json);
var token = JsonScanner.GetNextToken(buffer);
Assert.AreEqual(JsonTokenType.BeginObject, token.Type);
Assert.AreEqual("{", token.Lexeme);
Assert.AreEqual('x', buffer.Read());
}
示例8: TestEndOfFile
public void TestEndOfFile() {
var json = "\t ";
var buffer = new JsonBuffer(json);
var token = JsonScanner.GetNextToken(buffer);
Assert.AreEqual(JsonTokenType.EndOfFile, token.Type);
Assert.AreEqual("<eof>", token.Lexeme);
Assert.AreEqual(-1, buffer.Read());
}
示例9: Test3CharacterString
public void Test3CharacterString()
{
var json = "\t \"123\"x";
var buffer = new JsonBuffer(json);
var token = JsonScanner.GetNextToken(buffer);
Assert.AreEqual(JsonTokenType.String, token.Type);
Assert.AreEqual("123", token.StringValue);
Assert.AreEqual('x', buffer.Read());
}
示例10: FormatMessage
private static string FormatMessage(
string message,
JsonBuffer buffer,
int start
) {
var length = 20;
string snippet;
if (buffer.Position + length >= buffer.Length) {
snippet = buffer.Substring(start);
} else {
snippet = buffer.Substring(start, length) + "...";
}
return string.Format("{0} '{1}'.", message, snippet);
}
示例11: TestZeroPointZero
public void TestZeroPointZero()
{
var json = "\t 0.0,";
var buffer = new JsonBuffer(json);
var token = JsonScanner.GetNextToken(buffer);
Assert.AreEqual(JsonTokenType.Double, token.Type);
Assert.AreEqual("0.0", token.Lexeme);
Assert.AreEqual(',', buffer.Read());
}
示例12: TestUnquotedString
public void TestUnquotedString()
{
var json = "\t name123:1";
var buffer = new JsonBuffer(json);
var token = JsonScanner.GetNextToken(buffer);
Assert.AreEqual(JsonTokenType.UnquotedString, token.Type);
Assert.AreEqual("name123", token.StringValue);
Assert.AreEqual(':', buffer.Read());
}
示例13: TestZeroExponentMinusOne
public void TestZeroExponentMinusOne()
{
var json = "\t 0e-1,";
var buffer = new JsonBuffer(json);
var token = JsonScanner.GetNextToken(buffer);
Assert.AreEqual(JsonTokenType.Double, token.Type);
Assert.AreEqual("0e-1", token.Lexeme);
Assert.AreEqual(',', buffer.Read());
}
示例14: TestTrue
public void TestTrue()
{
var json = "\t true,";
var buffer = new JsonBuffer(json);
var token = JsonScanner.GetNextToken(buffer);
Assert.AreEqual(JsonTokenType.UnquotedString, token.Type);
Assert.AreEqual("true", token.StringValue);
Assert.AreEqual(',', buffer.Read());
}
示例15: TestTwelve
public void TestTwelve()
{
var json = "\t 12,";
var buffer = new JsonBuffer(json);
var token = JsonScanner.GetNextToken(buffer);
Assert.AreEqual(JsonTokenType.Int32, token.Type);
Assert.AreEqual("12", token.Lexeme);
Assert.AreEqual(',', buffer.Read());
}