本文整理汇总了C++中StringBuffer::Clear方法的典型用法代码示例。如果您正苦于以下问题:C++ StringBuffer::Clear方法的具体用法?C++ StringBuffer::Clear怎么用?C++ StringBuffer::Clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringBuffer
的用法示例。
在下文中一共展示了StringBuffer::Clear方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: s
TEST(Writer,DoublePrecision) {
const char json[] = "[1.2345,1.2345678,0.123456789012,1234567.8]";
StringBuffer buffer;
Writer<StringBuffer> writer(buffer);
const int kDefaultDoublePrecision = 6;
// handling the double precision
EXPECT_EQ(writer.GetDoublePrecision(), kDefaultDoublePrecision);
writer.SetDoublePrecision(17);
EXPECT_EQ(writer.GetDoublePrecision(), 17);
writer.SetDoublePrecision(-1); // negative equivalent to reset
EXPECT_EQ(writer.GetDoublePrecision(), kDefaultDoublePrecision);
writer.SetDoublePrecision(1);
writer.SetDoublePrecision(); // reset again
EXPECT_EQ(writer.GetDoublePrecision(), kDefaultDoublePrecision);
{ // write with explicitly increased precision
StringStream s(json);
Reader reader;
reader.Parse<0>(s, writer.SetDoublePrecision(12));
EXPECT_EQ(writer.GetDoublePrecision(), 12);
EXPECT_STREQ(json, buffer.GetString());
buffer.Clear();
}
{ // explicit individual double precisions
writer.SetDoublePrecision(2)
.StartArray()
.Double(1.2345,5)
.Double(1.2345678,9)
.Double(0.123456789012,12)
.Double(1234567.8,8)
.EndArray();
EXPECT_EQ(writer.GetDoublePrecision(), 2);
EXPECT_STREQ(json, buffer.GetString());
buffer.Clear();
}
{ // write with default precision (output with precision loss)
Document d;
d.Parse<0>(json);
d.Accept(writer.SetDoublePrecision());
// parsed again to avoid platform-dependent floating point outputs
// (e.g. width of exponents)
d.Parse<0>(buffer.GetString());
EXPECT_EQ(writer.GetDoublePrecision(), kDefaultDoublePrecision);
EXPECT_DOUBLE_EQ(d[0u].GetDouble(), 1.2345);
EXPECT_DOUBLE_EQ(d[1u].GetDouble(), 1.23457);
EXPECT_DOUBLE_EQ(d[2u].GetDouble(), 0.123457);
EXPECT_DOUBLE_EQ(d[3u].GetDouble(), 1234570);
buffer.Clear();
}
}
示例2: NATIVE_FUNCTION
AVES_API NATIVE_FUNCTION(aves_StringBuffer_clear)
{
StringBuffer *buf = THISV.Get<StringBuffer>();
buf->Clear();
VM_Push(thread, THISP);
RETURN_SUCCESS;
}
示例3:
TEST(StringBuffer, Clear) {
StringBuffer buffer;
buffer.Put('A');
buffer.Put('B');
buffer.Put('C');
buffer.Clear();
EXPECT_EQ(0u, buffer.GetSize());
EXPECT_STREQ("", buffer.GetString());
}
示例4: encode
string XJson::encode(const ::urbi::UValue& data) {
if (data.type != ::urbi::DATA_DICTIONARY && data.type != ::urbi::DATA_LIST) {
send("throw \"Only UList or UDictionary are supported by UJson.\";");
return "";
}
Document doc;
StringBuffer stream;
Writer<StringBuffer> writer(stream);
unique_ptr<Value> valPtr(fromUValue(data, doc.GetAllocator()));
(*valPtr).Accept(writer);
string result(stream.GetString());
stream.Clear();
return result;
}
示例5: sd
TEST(SchemaValidator, ValidateMetaSchema) {
CrtAllocator allocator;
char* json = ReadFile("draft-04/schema", allocator);
Document d;
d.Parse(json);
ASSERT_FALSE(d.HasParseError());
SchemaDocument sd(d);
SchemaValidator validator(sd);
if (!d.Accept(validator)) {
StringBuffer sb;
validator.GetInvalidSchemaPointer().StringifyUriFragment(sb);
printf("Invalid schema: %s\n", sb.GetString());
printf("Invalid keyword: %s\n", validator.GetInvalidSchemaKeyword());
sb.Clear();
validator.GetInvalidDocumentPointer().StringifyUriFragment(sb);
printf("Invalid document: %s\n", sb.GetString());
ADD_FAILURE();
}
CrtAllocator::Free(json);
}
示例6: s
TEST(SchemaValidatingWriter, Simple) {
Document sd;
sd.Parse("{\"type\":\"string\",\"minLength\":2,\"maxLength\":3}");
SchemaDocument s(sd);
Document d;
StringBuffer sb;
Writer<StringBuffer> writer(sb);
GenericSchemaValidator<SchemaDocument, Writer<StringBuffer> > validator(s, writer);
d.Parse("\"red\"");
EXPECT_TRUE(d.Accept(validator));
EXPECT_TRUE(validator.IsValid());
EXPECT_STREQ("\"red\"", sb.GetString());
sb.Clear();
validator.Reset();
d.Parse("\"ABCD\"");
EXPECT_FALSE(d.Accept(validator));
EXPECT_FALSE(validator.IsValid());
EXPECT_TRUE(validator.GetInvalidSchemaPointer() == SchemaDocument::PointerType(""));
EXPECT_TRUE(validator.GetInvalidDocumentPointer() == SchemaDocument::PointerType(""));
}
示例7: convertMultiple
void convertMultiple(const char* nameJSON, const char* nameCSV) {
//Prepare Input
struct stat statbuf;
stat(nameJSON, &statbuf);
size_t fsize = statbuf.st_size;
int fd = open(nameJSON, O_RDONLY);
if (fd == -1) {
throw runtime_error(string("json.open"));
}
const char *bufJSON = (const char*) mmap(NULL, fsize, PROT_READ, MAP_PRIVATE, fd, 0);
if (bufJSON == MAP_FAILED) {
throw runtime_error(string("json.mmap"));
}
//Prepare output
ofstream outFile;
outFile.open(nameCSV);
//Input loop
size_t obj_start = 0;
size_t obj_end = 0;
char *line_bufJSON = NULL;
StringBuffer buffer;
Writer<StringBuffer> writer(buffer);
stringstream ss;
int flushCount = 0;
while (obj_start < fsize) {
size_t i = obj_start;
for (; bufJSON[i] != '\n'; i++) {}
obj_end = i;
line_bufJSON = new char[obj_end - obj_start + 1];
line_bufJSON[obj_end - obj_start] = '\0';
memcpy(line_bufJSON, bufJSON + obj_start, obj_end - obj_start);
//Triggering parser
Document d;
d.Parse(line_bufJSON);
Value::ConstMemberIterator itrDoc = d.MemberBegin();
Value::ConstMemberIterator itrDocEnd = d.MemberEnd();
buffer.Clear();
writer.Reset(buffer);
//1st iteration unrolled to avoid unnecessary "if(first)" checks
if (itrDoc != itrDocEnd) {
if (itrDoc->value.IsObject()) {
Value::ConstMemberIterator itr_ = itrDoc->value.MemberBegin();
Value::ConstMemberIterator itrEnd_ = itrDoc->value.MemberEnd();
iterateObject(itr_, itrEnd_, &buffer, &writer, ss);
} else if (itrDoc->value.IsArray()) {
Value::ConstValueIterator itr_ = itrDoc->value.Begin();
Value::ConstValueIterator itrEnd_ = itrDoc->value.End();
iterateArray(itr_, itrEnd_, &buffer, &writer, ss);
} else if (itrDoc->value.IsBool()) {
ss << itrDoc->value.GetBool();
} else if (itrDoc->value.IsInt()) {
ss << itrDoc->value.GetInt();
} else if (itrDoc->value.IsInt64()) {
ss << itrDoc->value.GetInt64();
} else if (itrDoc->value.IsDouble()) {
ss << itrDoc->value.GetDouble();
} else if (itrDoc->value.IsString()) {
ss << "\"" << itrDoc->value.GetString() << "\"";
} else {
throw runtime_error(string("Case missing from tokenizer"));
}
}
itrDoc++;
iterateObject(itrDoc, itrDocEnd, &buffer, &writer, ss);
ss << "\n";
//flushing to output file every 1000 entries
flushCount++;
if(flushCount % 1000 == 0) {
outFile << ss.rdbuf();
ss.clear();
}
//Prepare next loop + cleanup
delete line_bufJSON;
obj_start = ++i;
}
outFile << ss.rdbuf();
outFile.close();
close(fd);
munmap((void*) bufJSON,fsize);
}
示例8: RemoveFromSSGS
// Removes Fallout 4 from GS, and it's config from My Games.
int RemoveFromSSGS() {
//////// Remove Game Events & Game Name from SSGS ////////
//////////////// -RemoveGameEvent- ////////////////
// Data.
const char* GameDataJson = "{\"game\":\"FALLOUT4\",\"event\":\"HEALTH\"}";
const char* GameData2Json = "{\"game\":\"FALLOUT4\",\"event\":\"STAMINA\"}";
const char* GameData3Json = "{\"game\":\"FALLOUT4\",\"event\":\"RADS\"}";
const char* GameData4Json = "{\"game\":\"FALLOUT4\",\"event\":\"WEIGHT\"}";
// Parsed JSON.
Document GameJsonParsed;
// Processed JSON ready be posted.
StringBuffer Buffer;
//// -HEALTH- ////
// Parse.
GameJsonParsed.Parse(GameDataJson);
// Format into buffer.
Writer<StringBuffer>writer(Buffer);
GameJsonParsed.Accept(writer);
// Post.
PostJson(Buffer, SSGS_ServerAddress_RemoveGameEvent);
// Cleanup.
Buffer.Clear();
//// -STAMINA- ////
// Parse.
GameJsonParsed.Parse(GameData2Json);
// Format into buffer.
Writer<StringBuffer>writer2(Buffer);
GameJsonParsed.Accept(writer2);
// Post.
PostJson(Buffer, SSGS_ServerAddress_RemoveGameEvent);
// Cleanup.
Buffer.Clear();
//// -RADS- ////
// Parse.
GameJsonParsed.Parse(GameData3Json);
// Format into buffer.
Writer<StringBuffer>writer3(Buffer);
GameJsonParsed.Accept(writer3);
// Post.
PostJson(Buffer, SSGS_ServerAddress_RemoveGameEvent);
// Cleanup.
Buffer.Clear();
//// -WEIGHT- ////
// Parse.
GameJsonParsed.Parse(GameData4Json);
// Format into buffer.
Writer<StringBuffer>writer4(Buffer);
GameJsonParsed.Accept(writer4);
// Post.
PostJson(Buffer, SSGS_ServerAddress_RemoveGameEvent);
// Cleanup.
Buffer.Clear();
//////////////// -RemoveGame- ////////////////
// Data.
const char* GameNameJson = "{\"game\":\"FALLOUT4\"}";
// Parse.
GameJsonParsed.Parse(GameNameJson);
// Format into buffer.
Writer<StringBuffer>writer5(Buffer);
GameJsonParsed.Accept(writer5);
// Post.
PostJson(Buffer, SSGS_ServerAddress_RemoveGame);
// Cleanup.
Buffer.Clear();
// Setup INI.
TCHAR INIPath[MAX_PATH];
GetEnvironmentVariable(L"USERPROFILE", INIPath, MAX_PATH);
_tcscat_s(INIPath, MAX_PATH, L"\\Documents\\My Games\\Fallout4\\SSGSPlugin_Fallout4.ini");
DeleteFile(INIPath);
return 0;
}
示例9: AddToSSGS
// Adds the game to SteelSeries Engine 3 GameSense.
int AddToSSGS() {
//////////////// -GameDataJson- ////////////////
// Data.
const char* GameDataJson = "{\"game\":\"FALLOUT4\",\"event\":\"HEALTH\",\"data\":{\"value\":0}}";
const char* GameData2Json = "{\"game\":\"FALLOUT4\",\"event\":\"STAMINA\",\"data\":{\"value\":0}}";
const char* GameData3Json = "{\"game\":\"FALLOUT4\",\"event\":\"RADS\",\"data\":{\"value\":0}}";
const char* GameData4Json = "{\"game\":\"FALLOUT4\",\"event\":\"WEIGHT\",\"data\":{\"value\":0}}";
// Parsed JSON.
Document GameJsonParsed;
// Processed JSON ready be posted.
StringBuffer Buffer;
//// -HEALTH- ////
// Parse.
GameJsonParsed.Parse(GameDataJson);
// Insert default value.
Value& STR = GameJsonParsed["data"]["value"];
STR.SetInt(100); // 100 Health default.
// Format into buffer.
Writer<StringBuffer>writer(Buffer);
GameJsonParsed.Accept(writer);
// Post.
PostJson(Buffer, SSGS_ServerAddress_GameEvent);
// Cleanup.
Buffer.Clear();
//// -STAMINA- ////
// Parse.
GameJsonParsed.Parse(GameData2Json);
// Insert default value.
Value& STR2 = GameJsonParsed["data"]["value"];
STR2.SetInt(100); // 100 Stamina default.
// Format into buffer.
Writer<StringBuffer>writer2(Buffer);
GameJsonParsed.Accept(writer2);
// Post.
PostJson(Buffer, SSGS_ServerAddress_GameEvent);
// Cleanup.
Buffer.Clear();
//// -RADS- ////
// Parse.
GameJsonParsed.Parse(GameData3Json);
// Insert default value.
Value& STR3 = GameJsonParsed["data"]["value"];
STR3.SetInt(0); // 0 RADS default.
// Format into buffer.
Writer<StringBuffer>writer3(Buffer);
GameJsonParsed.Accept(writer3);
// Post.
PostJson(Buffer, SSGS_ServerAddress_GameEvent);
// Cleanup.
Buffer.Clear();
//// -WEIGHT- ////
// Parse.
GameJsonParsed.Parse(GameData4Json);
// Insert default value.
Value& STR4 = GameJsonParsed["data"]["value"];
STR4.SetInt(100); // 100 WEIGHT default.
// Format into buffer.
Writer<StringBuffer>writer4(Buffer);
GameJsonParsed.Accept(writer4);
// Post.
PostJson(Buffer, SSGS_ServerAddress_GameEvent);
// Cleanup.
Buffer.Clear();
//////////////// -GameInterfaceJson- ////////////////
// Data.
const char* GameInterfaceJson = "{\"game\":\"FALLOUT4\",\"game_display_name\":\"Fallout 4\",\"icon_color_id\":5}";
//// -Interface- ////
// Parse.
GameJsonParsed.Parse(GameInterfaceJson);
// Insert default value.
Writer<StringBuffer>writer5(Buffer);
GameJsonParsed.Accept(writer5);
// Post.
PostJson(Buffer, SSGS_ServerAddress_GameMetadata);
// Cleanup.
Buffer.Clear();
//////////////// -GameInterfaceEventsJson- ////////////////
// Data.
const char* GameInterfaceEventsJson = "{\"game\":\"FALLOUT4\",\"event\":\"HEALTH\",\"min_value\":0,\"max_value\":100,\"icon_id\":1}";
const char* GameInterfaceEvents2Json = "{\"game\":\"FALLOUT4\",\"event\":\"STAMINA\",\"min_value\":0,\"max_value\":100,\"icon_id\":11}";
const char* GameInterfaceEvents3Json = "{\"game\":\"FALLOUT4\",\"event\":\"RADS\",\"min_value\":0,\"max_value\":100,\"icon_id\":6}";
const char* GameInterfaceEvents4Json = "{\"game\":\"FALLOUT4\",\"event\":\"WEIGHT\",\"min_value\":0,\"max_value\":100,\"icon_id\":17}";
//.........这里部分代码省略.........