MCPcopy Create free account
hub / github.com/dds-bridge/dds / splitIntoWords

Function splitIntoWords

library/tests/parse.cpp:654–695  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

652
653
654void splitIntoWords(
655 const string& text,
656 vector<string>& words)
657{
658 // Split into words (split on \s+, effectively).
659 unsigned Pos = 0;
660 unsigned startPos = 0;
661 bool isSpace = true;
662
663 // It seems compilers have different ideas about files.
664 const size_t tl = text.length();
665 string ttext;
666 if (text.back() == ' ')
667 ttext = text.substr(0, tl-1);
668 else if (text.at(tl-2) == ' ')
669 ttext = text.substr(0, tl-2);
670 else
671 ttext = text;
672
673 const unsigned l = static_cast<unsigned>(ttext.length());
674
675 while (Pos < l)
676 {
677 if (ttext.at(Pos) == ' ')
678 {
679 if (! isSpace)
680 {
681 words.push_back(ttext.substr(startPos, Pos-startPos));
682 isSpace = true;
683 }
684 }
685 else if (isSpace)
686 {
687 isSpace = false;
688 startPos = Pos;
689 }
690 Pos++;
691 }
692
693 if (! isSpace)
694 words.push_back(ttext.substr(startPos, Pos-startPos));
695}
696
697
698bool str2int(

Callers 2

read_fileFunction · 0.85
get_any_lineFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected