@@ -1658,16 +1658,30 @@ 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 (char ch : s) {
1669+ if (escaping) {
1670+ escaping = false ;
1671+ } else if (ch == escape) {
1672+ escaping = true ;
1673+ continue ;
1674+ } else if (ch == delim) {
1675+ if (!token.empty ()) {
1676+ elems.push_back (token);
1677+ }
1678+ token.clear ();
1679+ continue ;
1680+ }
1681+ token += ch;
16701682 }
1683+
1684+ elems.push_back (token);
16711685}
16721686
16731687static std::string JoinPath (const std::string &dir,
@@ -2483,7 +2497,7 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
24832497 token += 7 ;
24842498
24852499 std::vector<std::string> filenames;
2486- SplitString (std::string (token), ' ' , filenames);
2500+ SplitString (std::string (token), ' ' , ' \\ ' , filenames);
24872501
24882502 if (filenames.empty ()) {
24892503 if (warn) {
@@ -2891,7 +2905,7 @@ bool LoadObjWithCallback(std::istream &inStream, const callback_t &callback,
28912905 token += 7 ;
28922906
28932907 std::vector<std::string> filenames;
2894- SplitString (std::string (token), ' ' , filenames);
2908+ SplitString (std::string (token), ' ' , ' \\ ' , filenames);
28952909
28962910 if (filenames.empty ()) {
28972911 if (warn) {
0 commit comments