StyleSheetParser.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. /*
  2. * This source file is part of libRocket, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://www.librocket.com
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. *
  26. */
  27. #include "precompiled.h"
  28. #include "StyleSheetParser.h"
  29. #include <algorithm>
  30. #include "StyleSheetFactory.h"
  31. #include "StyleSheetNode.h"
  32. #include "../../Include/Rocket/Core/Log.h"
  33. #include "../../Include/Rocket/Core/StreamMemory.h"
  34. #include "../../Include/Rocket/Core/StyleSheet.h"
  35. #include "../../Include/Rocket/Core/StyleSheetSpecification.h"
  36. namespace Rocket {
  37. namespace Core {
  38. StyleSheetParser::StyleSheetParser()
  39. {
  40. line_number = 0;
  41. stream = NULL;
  42. parse_buffer_pos = 0;
  43. }
  44. StyleSheetParser::~StyleSheetParser()
  45. {
  46. }
  47. static bool IsValidIdentifier(const String& str)
  48. {
  49. if (str.empty())
  50. return false;
  51. for (int i = 0; i < str.size(); i++)
  52. {
  53. char c = str[i];
  54. bool valid = (
  55. (c >= 'a' && c <= 'z')
  56. || (c >= 'A' && c <= 'Z')
  57. || (c >= '0' && c <= '9')
  58. || (c == '-')
  59. || (c == '_')
  60. );
  61. if (!valid)
  62. return false;
  63. }
  64. return true;
  65. }
  66. static void PostprocessKeyframes(KeyframesMap& keyframes_map)
  67. {
  68. for (auto& keyframes_pair : keyframes_map)
  69. {
  70. Keyframes& keyframes = keyframes_pair.second;
  71. auto& blocks = keyframes.blocks;
  72. auto& property_ids = keyframes.property_ids;
  73. // Sort keyframes on selector value.
  74. std::sort(blocks.begin(), blocks.end(), [](const KeyframeBlock& a, const KeyframeBlock& b) { return a.normalized_time < b.normalized_time; });
  75. // Add all property names specified by any block
  76. if(blocks.size() > 0) property_ids.reserve(blocks.size() * blocks[0].properties.GetNumProperties());
  77. for(auto& block : blocks)
  78. {
  79. for (auto& property : block.properties.GetProperties())
  80. property_ids.push_back(property.first);
  81. }
  82. // Remove duplicate property names
  83. std::sort(property_ids.begin(), property_ids.end());
  84. property_ids.erase(std::unique(property_ids.begin(), property_ids.end()), property_ids.end());
  85. property_ids.shrink_to_fit();
  86. }
  87. }
  88. bool StyleSheetParser::ParseKeyframeBlock(KeyframesMap& keyframes_map, const String& identifier, const String& rules, const PropertyDictionary& properties)
  89. {
  90. if (!IsValidIdentifier(identifier))
  91. {
  92. Log::Message(Log::LT_WARNING, "Invalid keyframes identifier '%s' at %s:%d", identifier.c_str(), stream_file_name.c_str(), line_number);
  93. return false;
  94. }
  95. if (properties.GetNumProperties() == 0)
  96. return true;
  97. StringList rule_list;
  98. StringUtilities::ExpandString(rule_list, rules);
  99. std::vector<float> rule_values;
  100. rule_values.reserve(rule_list.size());
  101. for (auto rule : rule_list)
  102. {
  103. float value = 0.0f;
  104. int count = 0;
  105. rule = ToLower(rule);
  106. if (rule == "from")
  107. rule_values.push_back(0.0f);
  108. else if (rule == "to")
  109. rule_values.push_back(1.0f);
  110. else if(sscanf(rule.c_str(), "%f%%%n", &value, &count) == 1)
  111. if(count > 0 && value >= 0.0f && value <= 100.0f)
  112. rule_values.push_back(0.01f * value);
  113. }
  114. if (rule_values.empty())
  115. {
  116. Log::Message(Log::LT_WARNING, "Invalid keyframes rule(s) '%s' at %s:%d", rules.c_str(), stream_file_name.c_str(), line_number);
  117. return false;
  118. }
  119. Keyframes& keyframes = keyframes_map[identifier];
  120. for(float selector : rule_values)
  121. {
  122. auto it = std::find_if(keyframes.blocks.begin(), keyframes.blocks.end(), [selector](const KeyframeBlock& keyframe_block) { return Math::AbsoluteValue(keyframe_block.normalized_time - selector) < 0.0001f; });
  123. if (it == keyframes.blocks.end())
  124. {
  125. keyframes.blocks.push_back(KeyframeBlock{ selector });
  126. it = (keyframes.blocks.end() - 1);
  127. }
  128. else
  129. {
  130. // In case of duplicate keyframes, we only use the latest definition as per CSS rules
  131. it->properties = PropertyDictionary();
  132. }
  133. it->properties.Import(properties);
  134. }
  135. return true;
  136. }
  137. bool StyleSheetParser::ParseDecoratorBlock(DecoratorSpecificationMap& decorator_map, const String& at_name)
  138. {
  139. StringList name_type;
  140. StringUtilities::ExpandString(name_type, at_name, ':');
  141. if (name_type.size() != 2 || name_type[0].empty() || name_type[1].empty())
  142. {
  143. Log::Message(Log::LT_WARNING, "Decorator syntax error at %s:%d. Use syntax: '@decorator name : type { ... }'.", stream_file_name.c_str(), line_number);
  144. return false;
  145. }
  146. const String& name = name_type[0];
  147. String decorator_type = name_type[1];
  148. auto it_find = decorator_map.find(name);
  149. if (it_find != decorator_map.end())
  150. {
  151. Log::Message(Log::LT_WARNING, "Decorator with name '%s' already declared, ignoring decorator at %s:%d.", name.c_str(), stream_file_name.c_str(), line_number);
  152. return false;
  153. }
  154. // Get the property specification associated with the decorator type
  155. const PropertySpecification* property_specification = Factory::GetDecoratorPropertySpecification(decorator_type);
  156. PropertyDictionary properties;
  157. if(!property_specification)
  158. {
  159. // Type is not a declared decorator type, instead, see if it is another decorator name, then we inherit its properties.
  160. auto it = decorator_map.find(decorator_type);
  161. if (it != decorator_map.end())
  162. {
  163. // Yes, try to retrieve the property specification from the parent type, and add its property values.
  164. property_specification = Factory::GetDecoratorPropertySpecification(it->first);
  165. properties = it->second.properties;
  166. decorator_type = it->second.decorator_type;
  167. }
  168. // If we still don't have a property specification, we cannot continue.
  169. if (!property_specification)
  170. {
  171. Log::Message(Log::LT_WARNING, "Invalid decorator type '%s' declared at %s:%d.", decorator_type.c_str(), stream_file_name.c_str(), line_number);
  172. return false;
  173. }
  174. }
  175. if (!ReadProperties(properties, *property_specification))
  176. return false;
  177. Decorator* decorator = Factory::InstanceDecorator(decorator_type, properties);
  178. if (!decorator)
  179. {
  180. Log::Message(Log::LT_WARNING, "Could not instance decorator of type '%s' declared at %s:%d.", decorator_type.c_str(), stream_file_name.c_str(), line_number);
  181. return false;
  182. }
  183. decorator_map.emplace(name, DecoratorSpecification{ std::move(decorator_type), std::move(properties), decorator });
  184. return true;
  185. }
  186. int StyleSheetParser::Parse(StyleSheetNode* node, KeyframesMap& keyframes, DecoratorSpecificationMap& decorator_map, Stream* _stream)
  187. {
  188. int rule_count = 0;
  189. line_number = 0;
  190. stream = _stream;
  191. stream_file_name = Replace(stream->GetSourceURL().GetURL(), "|", ":");
  192. enum class State { Global, AtRuleIdentifier, AtRuleBlock, Invalid };
  193. State state = State::Global;
  194. // At-rules given by the following syntax in global space: @identifier name { block }
  195. enum class AtRule { None, Keyframes, Decorator };
  196. AtRule at_rule = AtRule::None;
  197. String at_rule_name;
  198. // Look for more styles while data is available
  199. while (FillBuffer())
  200. {
  201. String pre_token_str;
  202. while (char token = FindToken(pre_token_str, "{@}", true))
  203. {
  204. switch (state)
  205. {
  206. case State::Global:
  207. {
  208. if (token == '{')
  209. {
  210. // Read the attributes
  211. PropertyDictionary properties;
  212. if (!ReadProperties(properties, StyleSheetSpecification::GetPropertySpecification()))
  213. continue;
  214. StringList style_name_list;
  215. StringUtilities::ExpandString(style_name_list, pre_token_str);
  216. // Add style nodes to the root of the tree
  217. for (size_t i = 0; i < style_name_list.size(); i++)
  218. ImportProperties(node, style_name_list[i], properties, rule_count);
  219. rule_count++;
  220. }
  221. else if (token == '@')
  222. {
  223. state = State::AtRuleIdentifier;
  224. }
  225. else
  226. {
  227. Log::Message(Log::LT_WARNING, "Invalid character '%c' found while parsing stylesheet at %s:%d. Trying to proceed.", token, stream_file_name.c_str(), line_number);
  228. }
  229. }
  230. break;
  231. case State::AtRuleIdentifier:
  232. {
  233. if (token == '{')
  234. {
  235. String at_rule_identifier = pre_token_str.substr(0, pre_token_str.find(' '));
  236. at_rule_name = StringUtilities::StripWhitespace(pre_token_str.substr(at_rule_identifier.size()));
  237. if (at_rule_identifier == KEYFRAMES)
  238. {
  239. at_rule = AtRule::Keyframes;
  240. state = State::AtRuleBlock;
  241. }
  242. else if (at_rule_identifier == "decorator")
  243. {
  244. ParseDecoratorBlock(decorator_map, at_rule_name);
  245. at_rule = AtRule::None;
  246. at_rule_name.clear();
  247. state = State::Global;
  248. }
  249. else
  250. {
  251. // Invalid identifier, should ignore
  252. at_rule = AtRule::None;
  253. at_rule_name.clear();
  254. state = State::Global;
  255. Log::Message(Log::LT_WARNING, "Invalid at-rule identifier '%s' found in stylesheet at %s:%d", at_rule_identifier.c_str(), stream_file_name.c_str(), line_number);
  256. }
  257. }
  258. else
  259. {
  260. Log::Message(Log::LT_WARNING, "Invalid character '%c' found while parsing at-rule identifier in stylesheet at %s:%d", token, stream_file_name.c_str(), line_number);
  261. state = State::Invalid;
  262. }
  263. }
  264. break;
  265. case State::AtRuleBlock:
  266. {
  267. switch (at_rule)
  268. {
  269. case AtRule::Keyframes:
  270. {
  271. if (token == '{')
  272. {
  273. // Each keyframe in keyframes has its own block which is processed here
  274. state = State::AtRuleBlock;
  275. PropertyDictionary properties;
  276. if (!ReadProperties(properties, StyleSheetSpecification::GetPropertySpecification()))
  277. continue;
  278. if (!ParseKeyframeBlock(keyframes, at_rule_name, pre_token_str, properties))
  279. continue;
  280. }
  281. else if (token == '}')
  282. {
  283. at_rule = AtRule::None;
  284. at_rule_name.clear();
  285. state = State::Global;
  286. }
  287. else
  288. {
  289. Log::Message(Log::LT_WARNING, "Invalid character '%c' found while parsing keyframe block in stylesheet at %s:%d", token, stream_file_name.c_str(), line_number);
  290. state = State::Invalid;
  291. }
  292. }
  293. break;
  294. case AtRule::Decorator:
  295. {
  296. if (token == '{')
  297. {
  298. // Process the decorator
  299. ParseDecoratorBlock(decorator_map, at_rule_name);
  300. }
  301. else
  302. {
  303. Log::Message(Log::LT_WARNING, "Invalid character '%c' found while parsing decorator block in stylesheet at %s:%d", token, stream_file_name.c_str(), line_number);
  304. state = State::Invalid;
  305. }
  306. }
  307. break;
  308. case AtRule::None:
  309. {
  310. // Invalid at-rule, trying to continue
  311. if (token == '}')
  312. {
  313. at_rule = AtRule::None;
  314. at_rule_name.clear();
  315. state = State::Global;
  316. }
  317. }
  318. break;
  319. default:
  320. ROCKET_ERROR;
  321. }
  322. }
  323. break;
  324. default:
  325. ROCKET_ERROR;
  326. state = State::Invalid;
  327. break;
  328. }
  329. if (state == State::Invalid)
  330. break;
  331. }
  332. if (state == State::Invalid)
  333. break;
  334. }
  335. PostprocessKeyframes(keyframes);
  336. return rule_count;
  337. }
  338. bool StyleSheetParser::ParseProperties(PropertyDictionary& parsed_properties, const String& properties)
  339. {
  340. stream = new StreamMemory((const byte*)properties.c_str(), properties.size());
  341. bool success = ReadProperties(parsed_properties, StyleSheetSpecification::GetPropertySpecification());
  342. stream->RemoveReference();
  343. stream = NULL;
  344. return success;
  345. }
  346. bool StyleSheetParser::ReadProperties(PropertyDictionary& properties, const PropertySpecification& property_specification)
  347. {
  348. int rule_line_number = (int)line_number;
  349. String name;
  350. String value;
  351. enum ParseState { NAME, VALUE, QUOTE };
  352. ParseState state = NAME;
  353. char character;
  354. char previous_character = 0;
  355. while (ReadCharacter(character))
  356. {
  357. parse_buffer_pos++;
  358. switch (state)
  359. {
  360. case NAME:
  361. {
  362. if (character == ';')
  363. {
  364. name = StringUtilities::StripWhitespace(name);
  365. if (!name.empty())
  366. {
  367. Log::Message(Log::LT_WARNING, "Found name with no value while parsing property declaration '%s' at %s:%d", name.c_str(), stream_file_name.c_str(), line_number);
  368. name.clear();
  369. }
  370. }
  371. else if (character == '}')
  372. {
  373. name = StringUtilities::StripWhitespace(name);
  374. if (!StringUtilities::StripWhitespace(name).empty())
  375. Log::Message(Log::LT_WARNING, "End of rule encountered while parsing property declaration '%s' at %s:%d", name.c_str(), stream_file_name.c_str(), line_number);
  376. return true;
  377. }
  378. else if (character == ':')
  379. {
  380. name = StringUtilities::StripWhitespace(name);
  381. state = VALUE;
  382. }
  383. else
  384. name += character;
  385. }
  386. break;
  387. case VALUE:
  388. {
  389. if (character == ';')
  390. {
  391. value = StringUtilities::StripWhitespace(value);
  392. if (!property_specification.ParsePropertyDeclaration(properties, name, value, stream_file_name, rule_line_number))
  393. Log::Message(Log::LT_WARNING, "Syntax error parsing property declaration '%s: %s;' in %s: %d.", name.c_str(), value.c_str(), stream_file_name.c_str(), line_number);
  394. name.clear();
  395. value.clear();
  396. state = NAME;
  397. }
  398. else if (character == '}')
  399. {
  400. Log::Message(Log::LT_WARNING, "End of rule encountered while parsing property declaration '%s: %s;' in %s: %d.", name.c_str(), value.c_str(), stream_file_name.c_str(), line_number);
  401. return true;
  402. }
  403. else
  404. {
  405. value += character;
  406. if (character == '"')
  407. state = QUOTE;
  408. }
  409. }
  410. break;
  411. case QUOTE:
  412. {
  413. value += character;
  414. if (character == '"' && previous_character != '/')
  415. state = VALUE;
  416. }
  417. break;
  418. }
  419. previous_character = character;
  420. }
  421. if (!name.empty() || !value.empty())
  422. Log::Message(Log::LT_WARNING, "Invalid property declaration '%s':'%s' at %s:%d", name.c_str(), value.c_str(), stream_file_name.c_str(), line_number);
  423. return true;
  424. }
  425. // Updates the StyleNode tree, creating new nodes as necessary, setting the definition index
  426. bool StyleSheetParser::ImportProperties(StyleSheetNode* node, const String& names, const PropertyDictionary& properties, int rule_specificity)
  427. {
  428. StyleSheetNode* tag_node = NULL;
  429. StyleSheetNode* leaf_node = node;
  430. StringList nodes;
  431. StringUtilities::ExpandString(nodes, names, ' ');
  432. // Create each node going down the tree
  433. for (size_t i = 0; i < nodes.size(); i++)
  434. {
  435. String name = nodes[i];
  436. String tag;
  437. String id;
  438. StringList classes;
  439. StringList pseudo_classes;
  440. StringList structural_pseudo_classes;
  441. size_t index = 0;
  442. while (index < name.size())
  443. {
  444. size_t start_index = index;
  445. size_t end_index = index + 1;
  446. // Read until we hit the next identifier.
  447. while (end_index < name.size() &&
  448. name[end_index] != '#' &&
  449. name[end_index] != '.' &&
  450. name[end_index] != ':')
  451. end_index++;
  452. String identifier = name.substr(start_index, end_index - start_index);
  453. if (!identifier.empty())
  454. {
  455. switch (identifier[0])
  456. {
  457. case '#': id = identifier.substr(1); break;
  458. case '.': classes.push_back(identifier.substr(1)); break;
  459. case ':':
  460. {
  461. String pseudo_class_name = identifier.substr(1);
  462. if (StyleSheetFactory::GetSelector(pseudo_class_name) != NULL)
  463. structural_pseudo_classes.push_back(pseudo_class_name);
  464. else
  465. pseudo_classes.push_back(pseudo_class_name);
  466. }
  467. break;
  468. default: tag = identifier;
  469. }
  470. }
  471. index = end_index;
  472. }
  473. // Sort the classes and pseudo-classes so they are consistent across equivalent declarations that shuffle the
  474. // order around.
  475. std::sort(classes.begin(), classes.end());
  476. std::sort(pseudo_classes.begin(), pseudo_classes.end());
  477. std::sort(structural_pseudo_classes.begin(), structural_pseudo_classes.end());
  478. // Get the named child node.
  479. leaf_node = leaf_node->GetChildNode(tag, StyleSheetNode::TAG);
  480. tag_node = leaf_node;
  481. if (!id.empty())
  482. leaf_node = leaf_node->GetChildNode(id, StyleSheetNode::ID);
  483. for (size_t j = 0; j < classes.size(); ++j)
  484. leaf_node = leaf_node->GetChildNode(classes[j], StyleSheetNode::CLASS);
  485. for (size_t j = 0; j < structural_pseudo_classes.size(); ++j)
  486. leaf_node = leaf_node->GetChildNode(structural_pseudo_classes[j], StyleSheetNode::STRUCTURAL_PSEUDO_CLASS);
  487. for (size_t j = 0; j < pseudo_classes.size(); ++j)
  488. leaf_node = leaf_node->GetChildNode(pseudo_classes[j], StyleSheetNode::PSEUDO_CLASS);
  489. }
  490. // Merge the new properties with those already on the leaf node.
  491. leaf_node->ImportProperties(properties, rule_specificity);
  492. return true;
  493. }
  494. char StyleSheetParser::FindToken(String& buffer, const char* tokens, bool remove_token)
  495. {
  496. buffer.clear();
  497. char character;
  498. while (ReadCharacter(character))
  499. {
  500. if (strchr(tokens, character) != NULL)
  501. {
  502. if (remove_token)
  503. parse_buffer_pos++;
  504. return character;
  505. }
  506. else
  507. {
  508. buffer += character;
  509. parse_buffer_pos++;
  510. }
  511. }
  512. return 0;
  513. }
  514. // Attempts to find the next character in the active stream.
  515. bool StyleSheetParser::ReadCharacter(char& buffer)
  516. {
  517. bool comment = false;
  518. // Continuously fill the buffer until either we run out of
  519. // stream or we find the requested token
  520. do
  521. {
  522. while (parse_buffer_pos < parse_buffer.size())
  523. {
  524. if (parse_buffer[parse_buffer_pos] == '\n')
  525. line_number++;
  526. else if (comment)
  527. {
  528. // Check for closing comment
  529. if (parse_buffer[parse_buffer_pos] == '*')
  530. {
  531. parse_buffer_pos++;
  532. if (parse_buffer_pos >= parse_buffer.size())
  533. {
  534. if (!FillBuffer())
  535. return false;
  536. }
  537. if (parse_buffer[parse_buffer_pos] == '/')
  538. comment = false;
  539. }
  540. }
  541. else
  542. {
  543. // Check for an opening comment
  544. if (parse_buffer[parse_buffer_pos] == '/')
  545. {
  546. parse_buffer_pos++;
  547. if (parse_buffer_pos >= parse_buffer.size())
  548. {
  549. if (!FillBuffer())
  550. {
  551. buffer = '/';
  552. parse_buffer = "/";
  553. return true;
  554. }
  555. }
  556. if (parse_buffer[parse_buffer_pos] == '*')
  557. comment = true;
  558. else
  559. {
  560. buffer = '/';
  561. if (parse_buffer_pos == 0)
  562. parse_buffer.insert(parse_buffer_pos, 1, '/');
  563. else
  564. parse_buffer_pos--;
  565. return true;
  566. }
  567. }
  568. if (!comment)
  569. {
  570. // If we find a character, return it
  571. buffer = parse_buffer[parse_buffer_pos];
  572. return true;
  573. }
  574. }
  575. parse_buffer_pos++;
  576. }
  577. }
  578. while (FillBuffer());
  579. return false;
  580. }
  581. // Fills the internal buffer with more content
  582. bool StyleSheetParser::FillBuffer()
  583. {
  584. // If theres no data to process, abort
  585. if (stream->IsEOS())
  586. return false;
  587. // Read in some data (4092 instead of 4096 to avoid the buffer growing when we have to add back
  588. // a character after a failed comment parse.)
  589. parse_buffer.clear();
  590. bool read = stream->Read(parse_buffer, 4092) > 0;
  591. parse_buffer_pos = 0;
  592. return read;
  593. }
  594. }
  595. }