@@ -1658,16 +1658,31 @@ static bool exportGroupsToShape(shape_t *shape, const PrimGroup &prim_group,
16581658 return true ;
16591659}
16601660
1661- // Split a string with specified delimiter character.
1662- // http ://stackoverflow.com/questions/236129/split-a-string-in-c
1663- static void SplitString (const std::string &s, char delim,
1661+ // Split a string with specified delimiter character and escape character .
1662+ // https ://rosettacode.org/wiki/Tokenize_a_string_with_escaping#C.2B.2B
1663+ static void SplitString (const std::string &s, char delim, char escape,
16641664 std::vector<std::string> &elems) {
1665- std::stringstream ss;
1666- ss.str (s);
1667- std::string item;
1668- while (std::getline (ss, item, delim)) {
1669- elems.push_back (item);
1665+ std::string token;
1666+
1667+ bool escaping = false ;
1668+ for (int i = 0 ; i < s.size (); ++i) {
1669+ char ch = s[i];
1670+ if (escaping) {
1671+ escaping = false ;
1672+ } else if (ch == escape) {
1673+ escaping = true ;
1674+ continue ;
1675+ } else if (ch == delim) {
1676+ if (!token.empty ()) {
1677+ elems.push_back (token);
1678+ }
1679+ token.clear ();
1680+ continue ;
1681+ }
1682+ token += ch;
16701683 }
1684+
1685+ elems.push_back (token);
16711686}
16721687
16731688static std::string JoinPath (const std::string &dir,
@@ -2483,7 +2498,7 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
24832498 token += 7 ;
24842499
24852500 std::vector<std::string> filenames;
2486- SplitString (std::string (token), ' ' , filenames);
2501+ SplitString (std::string (token), ' ' , ' \\ ' , filenames);
24872502
24882503 if (filenames.empty ()) {
24892504 if (warn) {
@@ -2891,7 +2906,7 @@ bool LoadObjWithCallback(std::istream &inStream, const callback_t &callback,
28912906 token += 7 ;
28922907
28932908 std::vector<std::string> filenames;
2894- SplitString (std::string (token), ' ' , filenames);
2909+ SplitString (std::string (token), ' ' , ' \\ ' , filenames);
28952910
28962911 if (filenames.empty ()) {
28972912 if (warn) {
0 commit comments