split_line

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen Revision Vorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
split_line [04.01.2006 16:05 (vor 19 Jahren)] cwachasplit_line [16.11.2016 23:18 (vor 8 Jahren)] (aktuell) – Externe Bearbeitung 127.0.0.1
Zeile 30: Zeile 30:
     return 0;     return 0;
 } }
 +</code>
 +
 +Output:
 +<code>
 +Tokens:
 +'Writing'
 +'programs'
 +'in C++'
 +'is'
 +'Fun!!'
 </code> </code>
 === Documentation === === Documentation ===
  
-A more complex example can be found in [[configparser]] in function readFile(). The function resembles a state machine with 5 states (see enum SPLIT_LINE_STATE). It is possible to provide the starting state of the machine which gives you the ability to resume tokenization of a string in some cases. In resuming mode (start_state != SL_NORMAL) the read in characters are appended to the last string in the string vector //ret// until the state switches back to SL_NORMAL. In [[configparser]] this behaviour was used to read in multiline values. However this features does not give you the ability to split a string anywhere yourself and then pass it over to split_line (using the return state as new start_state). The outcome will be different from what you might expect in most cases!+A more complex example can be found in [[cfg_parser]] in function readFile(). The function resembles a state machine with 5 states (see enum SPLIT_LINE_STATE). It is possible to provide the starting state of the machine which gives you the ability to resume tokenization of a string in some cases. In resuming mode (start_state != SL_NORMAL) the read in characters are appended to the last string in the string vector //ret// until the state switches back to SL_NORMAL. In [[cfg_parser]] this behaviour was used to read in multiline values. However this features does not give you the ability to split a string anywhere yourself and then pass it over to split_line (using the return state as new start_state). The outcome will be different from what you might expect in most cases!
  
 <code cpp> <code cpp>
Zeile 49: Zeile 59:
 int split_line(std::vector<std::string>& ret, std::string& line, const std::string& delimiters = " \t\r\n", char escape_char = '\\', char safemode_char = '"', char comment_char = '\0', int start_state = SL_NORMAL); int split_line(std::vector<std::string>& ret, std::string& line, const std::string& delimiters = " \t\r\n", char escape_char = '\\', char safemode_char = '"', char comment_char = '\0', int start_state = SL_NORMAL);
 </code> </code>
 +
 +== State Diagram ==
 +
 +{{ projects:splitline.png }}
 +
 +**Legend**
 +
 +  * character read in / action
 +  * eat: append the character to the current token
 +  * finish: append token to token list and start with a new token
 +
 +
 +=== License ===
 +
 +<html>
 +
 +<!-- Creative Commons License -->
 +<a href="http://creativecommons.org/licenses/GPL/2.0/">
 +<img alt="CC-GNU GPL" border="0" src="http://creativecommons.org/images
 +/public/cc-GPL-a.png" /></a><br />
 +This software is licensed under the <a href="http://creativecommons.org/licenses/GPL/2.0/">CC-GNU GPL</a>.
 +<!-- /Creative Commons License -->
 +
 +<!--
 +
 +<rdf:RDF xmlns="http://web.resource.org/cc/"
 +    xmlns:dc="http://purl.org/dc/elements/1.1/"
 +    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
 +<Work rdf:about="">
 +   <license rdf:resource="http://creativecommons.org/licenses/GPL/2.0/" />
 +   <dc:type rdf:resource="http://purl.org/dc/dcmitype/Software" />
 +</Work>
 +
 +<License rdf:about="http://creativecommons.org/licenses/GPL/2.0/">
 +<permits rdf:resource="http://web.resource.org/cc/Reproduction" />
 +   <permits rdf:resource="http://web.resource.org/cc/Distribution" />
 +   <requires rdf:resource="http://web.resource.org/cc/Notice" />
 +   <permits rdf:resource="http://web.resource.org/cc/DerivativeWorks" />
 +   <requires rdf:resource="http://web.resource.org/cc/ShareAlike" />
 +   <requires rdf:resource="http://web.resource.org/cc/SourceCode" />
 +</License>
 +
 +</rdf:RDF>
 +
 +-->
 +
 +</html>
 +
  
  • split_line.1136387101.txt.gz
  • Zuletzt geändert: 16.11.2016 23:16 (vor 8 Jahren)
  • (Externe Bearbeitung)