tc_json.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  1. #include "util/tc_json.h"
  2. #include <math.h>
  3. #include <sstream>
  4. #include <iostream>
  5. #include <iomanip>
  6. #include "util/tc_common.h"
  7. namespace tars
  8. {
  9. #define FILTER_SPACE while(isspace((int)c)) {c=reader.read();}
  10. JsonValuePtr TC_Json::getValue(BufferJsonReader & reader)
  11. {
  12. char c=reader.read();
  13. FILTER_SPACE;
  14. switch(c)
  15. {
  16. case '{':
  17. return getObj(reader);
  18. break;
  19. case '[':
  20. return getArray(reader);
  21. break;
  22. case '"':
  23. //case '\'':
  24. return getString(reader,c);
  25. break;
  26. case 'T':
  27. case 't':
  28. case 'F':
  29. case 'f':
  30. return getBoolean(reader,c);
  31. break;
  32. case '0':
  33. case '1':
  34. case '2':
  35. case '3':
  36. case '4':
  37. case '5':
  38. case '6':
  39. case '7':
  40. case '8':
  41. case '9':
  42. case '-':
  43. return getNum(reader,c);
  44. break;
  45. case 'n':
  46. case 'N':
  47. return getNull(reader,c);
  48. default:
  49. char s[64];
  50. snprintf(s, sizeof(s), "buffer overflow when peekBuf, over %u.", (uint32_t)(uint32_t)reader.getCur());
  51. throw TC_Json_Exception(s);
  52. }
  53. }
  54. JsonValueObjPtr TC_Json::getObj(BufferJsonReader & reader)
  55. {
  56. JsonValueObjPtr p = new JsonValueObj();
  57. bool bFirst=true;
  58. while(1)
  59. {
  60. char c=reader.read();
  61. FILTER_SPACE;
  62. if(c == '}' && bFirst)
  63. {
  64. return p;
  65. }
  66. bFirst=false;
  67. if(c != '"')
  68. {
  69. char s[64];
  70. snprintf(s, sizeof(s), "get obj error(key is not string)[pos:%u]", (uint32_t)reader.getCur());
  71. throw TC_Json_Exception(s);
  72. }
  73. JsonValueStringPtr pString=getString(reader);
  74. c=reader.read();
  75. FILTER_SPACE;
  76. if(c != ':')
  77. {
  78. char s[64];
  79. snprintf(s, sizeof(s), "get obj error(: not find)[pos:%u]", (uint32_t)reader.getCur());
  80. throw TC_Json_Exception(s);
  81. }
  82. JsonValuePtr pValue=getValue(reader);
  83. p->value[pString->value]=pValue;
  84. c=reader.read();
  85. FILTER_SPACE;
  86. if(c == ',')
  87. continue;
  88. if(c == '}')
  89. return p;
  90. char s[64];
  91. snprintf(s, sizeof(s), "get obj error(, not find)[pos:%u]", (uint32_t)reader.getCur());
  92. throw TC_Json_Exception(s);
  93. }
  94. }
  95. JsonValueArrayPtr TC_Json::getArray(BufferJsonReader & reader)
  96. {
  97. JsonValueArrayPtr p = new JsonValueArray();
  98. bool bFirst=true;
  99. while(1)
  100. {
  101. char c;
  102. if(bFirst)
  103. {
  104. c=reader.read();
  105. FILTER_SPACE;
  106. if(c == ']')
  107. {
  108. return p;
  109. }
  110. reader.back();
  111. }
  112. bFirst=false;
  113. JsonValuePtr pValue=getValue(reader);
  114. p->push_back(pValue);
  115. c=reader.read();
  116. FILTER_SPACE;
  117. if(c == ',')
  118. continue;
  119. if(c == ']')
  120. return p;
  121. char s[64];
  122. snprintf(s, sizeof(s), "get vector error(, not find )[pos:%u]", (uint32_t)reader.getCur());
  123. throw TC_Json_Exception(s);
  124. }
  125. }
  126. JsonValueStringPtr TC_Json::getString(BufferJsonReader & reader,char head)
  127. {
  128. JsonValueStringPtr p = new JsonValueString();
  129. const char * pChar=reader.getPoint();
  130. char c;
  131. uint32_t i=0;
  132. while(1)
  133. {
  134. c=reader.read();
  135. if(c == '\\')
  136. {
  137. p->value.append(pChar,i);
  138. pChar=pChar+i+2;
  139. i=0;
  140. c=reader.read();
  141. if(c == '\\' || c == '\"' || c == '/')
  142. p->value.append(1,c);
  143. else if(c == 'b')
  144. p->value.append(1,'\b');
  145. else if(c == 'f')
  146. p->value.append(1,'\f');
  147. else if(c == 'n')
  148. p->value.append(1,'\n');
  149. else if(c == 'r')
  150. p->value.append(1,'\r');
  151. else if(c == 't')
  152. p->value.append(1,'\t');
  153. else if(c == 'u')
  154. {
  155. uint32_t iCode=getHex(reader);
  156. if (iCode < 0x00080)
  157. {
  158. p->value.append(1,(char)(iCode & 0xFF));
  159. }
  160. else if (iCode < 0x00800)
  161. {
  162. p->value.append(1,(char)(0xC0 + ((iCode >> 6) & 0x1F)));
  163. p->value.append(1,(char)(0x80 + (iCode & 0x3F)));
  164. }
  165. else if (iCode < 0x10000)
  166. {
  167. p->value.append(1,(char)(0xE0 + ((iCode >> 12) & 0x0F)));
  168. p->value.append(1,(char)(0x80 + ((iCode >> 6) & 0x3F)));
  169. p->value.append(1,(char)(0x80 + (iCode & 0x3F)));
  170. }
  171. else
  172. {
  173. p->value.append(1,(char)(0xF0 + ((iCode >> 18) & 0x07)));
  174. p->value.append(1,(char)(0x80 + ((iCode >> 12) & 0x3F)));
  175. p->value.append(1,(char)(0x80 + ((iCode >> 6) & 0x3F)));
  176. p->value.append(1,(char)(0x80 + (iCode & 0x3F)));
  177. }
  178. pChar+=4;
  179. // char s[64];
  180. // snprintf(s, sizeof(s), "get string error1(\\u)[pos:%u], code:%x", (uint32_t)reader.getCur(), iCode);
  181. // cout << s << endl;
  182. //
  183. // if(iCode>0xff)
  184. // {
  185. // char s[64];
  186. // snprintf(s, sizeof(s), "get string error1(\\u)[pos:%u], code:%x", (uint32_t)reader.getCur(), iCode);
  187. // throw TC_Json_Exception(s);
  188. // }
  189. // pChar+=4;
  190. // p->value.append(1,(char)iCode);
  191. //#if 0
  192. // //还要再读一个
  193. // if(iCode<0xd800)
  194. // {
  195. // p->value.append(1,(char)(iCode>>2&0x00ff));
  196. // p->value.append(1,(char)(iCode&0x00ff));
  197. // }
  198. // else
  199. // {
  200. // uint16_t iCodeTwelve=0;
  201. // c=reader.read();
  202. // if(c == '\\' && (c=reader.read(),c=='u'))
  203. // {
  204. // iCodeTwelve=getHex();
  205. // }
  206. // if(iCodeTwelve<0xdc00)
  207. // {
  208. // char s[64];
  209. // snprintf(s, sizeof(s), "get string error2(\\u)[pos:%u]", (uint32_t)reader.getCur());
  210. // throw TC_Json_Exception(s);
  211. // }
  212. // int iBuf=0;
  213. // iCode=iCode&0x03ff;
  214. // iBuf=(iCode<10);
  215. // iBuf+=(iCodeTwelve&0x03ff);
  216. // iBuf+=0x10000;
  217. // }
  218. //#endif
  219. }
  220. }
  221. else if(c==head)
  222. break;
  223. else
  224. i++;
  225. }
  226. p->value.append(pChar,i);
  227. return p;
  228. }
  229. JsonValueNumPtr TC_Json::getNum(BufferJsonReader & reader,char head)
  230. {
  231. bool bOk=true;
  232. bool bFloat=false;
  233. bool bExponential=false;
  234. bool bNegative=false;
  235. bool bExponentialNegative=false;
  236. int64_t iInt=0;
  237. double dFloat=0;
  238. double dFloatRat=0;
  239. int64_t iExponential=0;
  240. if(head == '-')
  241. {
  242. bOk=false;
  243. bNegative=true;
  244. }
  245. else
  246. iInt=head-0x30;
  247. char c;
  248. bool bNeedBack=false;
  249. while(1)
  250. {
  251. if(reader.hasEnd())
  252. break;
  253. c=reader.read();
  254. if(c>=0x30 && c<=0x39)
  255. {
  256. bOk=true;
  257. if(bExponential)
  258. iExponential=iExponential*10+c-0x30;
  259. else if(bFloat)
  260. {
  261. dFloat=dFloat+dFloatRat*(c-0x30);
  262. dFloatRat=dFloatRat*0.1;
  263. }
  264. else
  265. iInt=iInt*10+c-0x30;
  266. }
  267. else if(c == '.' && !bFloat && !bExponential && bOk)
  268. {
  269. bOk=false;
  270. bFloat=true;
  271. dFloatRat=0.1;
  272. }
  273. else if((c == 'e' || c == 'E') && !bExponential && bOk)
  274. {
  275. bOk=false;
  276. bExponential=true;
  277. iExponential=0;
  278. if(reader.hasEnd())
  279. break;
  280. c=reader.read();
  281. if(c == '-')
  282. bExponentialNegative=true;
  283. else if(c == '+')
  284. bExponentialNegative=false;
  285. else if(c>=0x30 && c<=0x39)
  286. {
  287. bOk=true;
  288. bExponential=(bool)(c-0x30);
  289. }
  290. else
  291. {
  292. bNeedBack=true;
  293. break;
  294. }
  295. }
  296. else
  297. {
  298. bNeedBack=true;
  299. break;
  300. }
  301. }
  302. if(!bOk)
  303. {
  304. char s[64];
  305. snprintf(s, sizeof(s), "get num error[pos:%u]", (uint32_t)reader.getCur());
  306. throw TC_Json_Exception(s);
  307. }
  308. if(bNeedBack)
  309. reader.back();
  310. if(bExponentialNegative)
  311. iExponential=0-iExponential;
  312. JsonValueNumPtr p = new JsonValueNum();
  313. p->isInt=!bFloat;
  314. if(bFloat)
  315. {
  316. double dResult=(iInt+dFloat)*pow(10,iExponential);
  317. if(bNegative)
  318. dResult=0-dResult;
  319. p->value=dResult;
  320. p->lvalue=dResult;
  321. }
  322. else
  323. {
  324. if(bNegative)
  325. iInt =0-iInt ;
  326. p->lvalue=iInt;
  327. p->value=iInt;
  328. }
  329. return p;
  330. }
  331. //为了提高效率和代码好写就先这么写了
  332. JsonValueBooleanPtr TC_Json::getBoolean(BufferJsonReader & reader,char c)
  333. {
  334. bool bOk=false;
  335. bool bValue;
  336. if(c=='t'||c=='T')
  337. {
  338. c=reader.read();
  339. if(c=='r'||c=='R')
  340. {
  341. c=reader.read();
  342. if(c=='u'||c=='U')
  343. {
  344. c=reader.read();
  345. if(c=='e'||c=='E')
  346. {
  347. bValue=true;
  348. bOk=true;
  349. }
  350. }
  351. }
  352. }
  353. else if(c=='f'||c=='F')
  354. {
  355. c=reader.read();
  356. if(c=='a'||c=='A')
  357. {
  358. c=reader.read();
  359. if(c=='l'||c=='L')
  360. {
  361. c=reader.read();
  362. if(c=='s'||c=='S')
  363. {
  364. c=reader.read();
  365. if(c=='e'||c=='E')
  366. {
  367. bValue=false;
  368. bOk=true;
  369. }
  370. }
  371. }
  372. }
  373. }
  374. if(!bOk)
  375. {
  376. char s[64];
  377. snprintf(s, sizeof(s), "get bool error[pos:%u]", (uint32_t)reader.getCur());
  378. throw TC_Json_Exception(s);
  379. }
  380. JsonValueBooleanPtr p = new JsonValueBoolean();
  381. p->value=bValue;
  382. return p;
  383. }
  384. JsonValueNullPtr TC_Json::getNull(BufferJsonReader & reader,char c)
  385. {
  386. JsonValueNullPtr p = new JsonValueNull();
  387. assert(c=='n' || c=='N');
  388. bool bOk=false;
  389. c=reader.read();
  390. if(c=='u'||c=='U')
  391. {
  392. c=reader.read();
  393. if(c=='l'||c=='L')
  394. {
  395. c=reader.read();
  396. if(c=='l'||c=='L')
  397. {
  398. bOk=true;
  399. }
  400. }
  401. }
  402. if(!bOk)
  403. {
  404. char s[64];
  405. snprintf(s, sizeof(s), "get NULL error[pos:%u]", (uint32_t)reader.getCur());
  406. throw TC_Json_Exception(s);
  407. }
  408. //return NULL;
  409. return p;
  410. }
  411. uint32_t TC_Json::getHex(BufferJsonReader & reader)
  412. {
  413. uint32_t iCode=0;
  414. char c;
  415. for(int iLoop=0;iLoop<4;iLoop++)
  416. {
  417. c=reader.read();
  418. if(c>='a'&&c<='f')
  419. iCode=iCode*16+c-'a'+10;
  420. else if(c>='A'&&c<='F')
  421. iCode=iCode*16+c-'A'+10;
  422. else if(c>='0'&&c<='9')
  423. iCode=iCode*16+c-'0';
  424. else
  425. {
  426. char s[64];
  427. snprintf(s, sizeof(s), "get string error3(\\u)[pos:%u]", (uint32_t)reader.getCur());
  428. throw TC_Json_Exception(s);
  429. }
  430. }
  431. return iCode;
  432. }
  433. string TC_Json::writeValue(const JsonValuePtr & p, bool withSpace)
  434. {
  435. string ostr;
  436. writeValue(p, ostr, withSpace);
  437. return ostr;
  438. }
  439. void TC_Json::writeValue(const JsonValuePtr& p, vector<char>& buf, bool withSpace)
  440. {
  441. string ostr;
  442. writeValue(p, ostr, withSpace);
  443. buf.assign(ostr.begin(), ostr.end());
  444. }
  445. void TC_Json::writeValue(const JsonValuePtr & p, string& ostr, bool withSpace)
  446. {
  447. if(!p)
  448. {
  449. ostr += "null";
  450. return;
  451. }
  452. switch(p->getType())
  453. {
  454. case eJsonTypeString :
  455. writeString(JsonValueStringPtr::dynamicCast(p), ostr);
  456. break;
  457. case eJsonTypeNum:
  458. writeNum(JsonValueNumPtr::dynamicCast(p), ostr);
  459. break;
  460. case eJsonTypeObj:
  461. writeObj(JsonValueObjPtr::dynamicCast(p), ostr, withSpace);
  462. break;
  463. case eJsonTypeArray:
  464. writeArray(JsonValueArrayPtr::dynamicCast(p), ostr, withSpace);
  465. break;
  466. case eJsonTypeBoolean:
  467. writeBoolean(JsonValueBooleanPtr::dynamicCast(p), ostr);
  468. break;
  469. default:
  470. assert(false);
  471. }
  472. }
  473. void TC_Json::writeString(const JsonValueStringPtr & p, string& ostr)
  474. {
  475. writeString(p->value, ostr);
  476. }
  477. void TC_Json::writeString(const string & s, string& ostr)
  478. {
  479. ostr += "\"";
  480. std::string::const_iterator it(s.begin()),
  481. itEnd(s.end());
  482. for (; it != itEnd; ++it)
  483. {
  484. switch(*it)
  485. {
  486. case '"':
  487. ostr += "\\\"";
  488. break;
  489. case '\\':
  490. ostr += "\\\\";
  491. break;
  492. case '/':
  493. ostr += "\\/";
  494. break;
  495. case '\b':
  496. ostr += "\\b";
  497. break;
  498. case '\f':
  499. ostr += "\\f";
  500. break;
  501. case '\n':
  502. ostr += "\\n";
  503. break;
  504. case '\r':
  505. ostr += "\\r";
  506. break;
  507. case '\t':
  508. ostr += "\\t";
  509. break;
  510. default:
  511. {
  512. if((unsigned char)(*it)<0x20)
  513. {
  514. char buf[16];
  515. snprintf(buf,sizeof(buf),"\\u%04x",(unsigned char)*it);
  516. ostr += string(buf,6);
  517. }
  518. else
  519. {
  520. ostr.push_back(*it);
  521. }
  522. break;
  523. }
  524. }
  525. }
  526. ostr += "\"";
  527. }
  528. void TC_Json::writeNum(const JsonValueNumPtr & p, string& ostr)
  529. {
  530. ostringstream ss;
  531. if (std::isnan(p->value))
  532. {
  533. ss << "null";
  534. }
  535. else if (!p->isInt)
  536. {
  537. ss << TC_Common::tostr(p->value) ;
  538. }
  539. else
  540. {
  541. ss << (int64_t)p->lvalue;
  542. }
  543. ostr += ss.str();
  544. }
  545. void TC_Json::writeObj(const JsonValueObjPtr & p, string& ostr, bool withSpace)
  546. {
  547. ostr += (withSpace ? "{ " : "{");
  548. unordered_map<string,JsonValuePtr>::const_iterator it(p->value.begin()), it_end(p->value.end());
  549. while (it != it_end)
  550. {
  551. writeString(it->first, ostr);
  552. ostr += (withSpace ? ": " : ":");
  553. writeValue(it->second, ostr);
  554. if(++it != it_end)
  555. {
  556. ostr += (withSpace ? ", " : ",");
  557. }
  558. }
  559. ostr += (withSpace ? " }" : "}");
  560. }
  561. void TC_Json::writeArray(const JsonValueArrayPtr & p, string& ostr, bool withSpace)
  562. {
  563. ostr += (withSpace ? "[ " : "[");
  564. vector<JsonValuePtr>::const_iterator it(p->value.begin()), it_end(p->value.end());
  565. while (it != it_end)
  566. {
  567. writeValue(*it, ostr);
  568. if (++it != it_end)
  569. {
  570. ostr += (withSpace ? ", " : ",");
  571. }
  572. }
  573. ostr += (withSpace ? " ]" : "]");
  574. }
  575. void TC_Json::writeBoolean(const JsonValueBooleanPtr & p, string& ostr)
  576. {
  577. if(p->value)
  578. ostr += "true";
  579. else
  580. ostr += "false";
  581. }
  582. JsonValuePtr TC_Json::getValue(const string & str)
  583. {
  584. BufferJsonReader reader;
  585. reader.setBuffer(str.c_str(),str.length());
  586. return getValue(reader);
  587. }
  588. JsonValuePtr TC_Json::getValue(const vector<char>& buf)
  589. {
  590. BufferJsonReader reader;
  591. reader.setBuffer(buf);
  592. return getValue(reader);
  593. }
  594. //json里面定义的空白字符
  595. bool TC_Json::isspace(char c)
  596. {
  597. if(c == ' ' || c == '\t' || c == '\r' || c == '\n')
  598. return true;
  599. return false;
  600. }
  601. //////////////////////////////////////////////////////
  602. void TC_JsonWriteOstream::writeValue(const JsonValuePtr & p, ostream& ostr, bool withSpace)
  603. {
  604. if(!p)
  605. {
  606. ostr << "null";
  607. return;
  608. }
  609. switch(p->getType())
  610. {
  611. case eJsonTypeString :
  612. writeString(JsonValueStringPtr::dynamicCast(p), ostr);
  613. break;
  614. case eJsonTypeNum:
  615. writeNum(JsonValueNumPtr::dynamicCast(p), ostr);
  616. break;
  617. case eJsonTypeObj:
  618. writeObj(JsonValueObjPtr::dynamicCast(p), ostr, withSpace);
  619. break;
  620. case eJsonTypeArray:
  621. writeArray(JsonValueArrayPtr::dynamicCast(p), ostr, withSpace);
  622. break;
  623. case eJsonTypeBoolean:
  624. writeBoolean(JsonValueBooleanPtr::dynamicCast(p), ostr);
  625. break;
  626. default:
  627. assert(false);
  628. }
  629. }
  630. void TC_JsonWriteOstream::writeString(const JsonValueStringPtr & p, ostream& sReturn)
  631. {
  632. writeString(p->value, sReturn);
  633. }
  634. void TC_JsonWriteOstream::writeString(const string & s, ostream& sReturn)
  635. {
  636. sReturn << "\"";
  637. std::string::const_iterator it(s.begin()),
  638. itEnd(s.end());
  639. for (; it != itEnd; ++it)
  640. {
  641. switch(*it)
  642. {
  643. case '"':
  644. sReturn << "\\\"";
  645. break;
  646. case '\\':
  647. sReturn << "\\\\";
  648. break;
  649. case '/':
  650. sReturn <<"\\/";
  651. break;
  652. case '\b':
  653. sReturn << "\\b";
  654. break;
  655. case '\f':
  656. sReturn << "\\f";
  657. break;
  658. case '\n':
  659. sReturn << "\\n";
  660. break;
  661. case '\r':
  662. sReturn << "\\r";
  663. break;
  664. case '\t':
  665. sReturn << "\\t";
  666. break;
  667. default:
  668. {
  669. if((unsigned char)(*it)<0x20)
  670. {
  671. char buf[16];
  672. snprintf(buf,sizeof(buf),"\\u%04x",(unsigned char)*it);
  673. sReturn << string(buf,6);
  674. }
  675. else
  676. {
  677. sReturn << *it;
  678. }
  679. break;
  680. }
  681. }
  682. }
  683. sReturn << "\"";
  684. }
  685. void TC_JsonWriteOstream::writeNum(const JsonValueNumPtr & p, ostream& ostr)
  686. {
  687. if (!p->isInt)
  688. {
  689. ostr << TC_Common::tostr(p->value);
  690. }
  691. else
  692. {
  693. ostr << (int64_t)p->lvalue;
  694. }
  695. }
  696. void TC_JsonWriteOstream::writeObj(const JsonValueObjPtr & p, ostream& ostr, bool withSpace)
  697. {
  698. ostr << "{" << (withSpace ? " " : "");
  699. unordered_map<string,JsonValuePtr>::const_iterator it(p->value.begin()), it_end(p->value.end());
  700. while (it != it_end)
  701. {
  702. writeString(it->first, ostr);
  703. ostr << ":" << (withSpace ? " " : "");
  704. writeValue(it->second, ostr);
  705. if(++it != it_end)
  706. {
  707. ostr << "," << (withSpace ? " " : "");
  708. }
  709. }
  710. ostr << (withSpace ? " " : "") << "}";
  711. }
  712. void TC_JsonWriteOstream::writeArray(const JsonValueArrayPtr & p, ostream& ostr, bool withSpace)
  713. {
  714. ostr << "[" << (withSpace ? " " : "");
  715. vector<JsonValuePtr>::const_iterator it(p->value.begin()), it_end(p->value.end());
  716. while (it != it_end)
  717. {
  718. writeValue(*it, ostr);
  719. if (++it != it_end)
  720. {
  721. ostr << "," << (withSpace ? " " : "");
  722. }
  723. }
  724. ostr << (withSpace ? " " : "") << "]";
  725. }
  726. void TC_JsonWriteOstream::writeBoolean(const JsonValueBooleanPtr & p, ostream& ostr)
  727. {
  728. if(p->value)
  729. ostr << "true";
  730. else
  731. ostr << "false";
  732. }
  733. }