@@ -1658,16 +1658,31 @@ static bool exportGroupsToShape(shape_t *shape, const PrimGroup &prim_group,
1658
1658
return true ;
1659
1659
}
1660
1660
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,
1664
1664
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;
1670
1683
}
1684
+
1685
+ elems.push_back (token);
1671
1686
}
1672
1687
1673
1688
static std::string JoinPath (const std::string &dir,
@@ -2483,7 +2498,7 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
2483
2498
token += 7 ;
2484
2499
2485
2500
std::vector<std::string> filenames;
2486
- SplitString (std::string (token), ' ' , filenames);
2501
+ SplitString (std::string (token), ' ' , ' \\ ' , filenames);
2487
2502
2488
2503
if (filenames.empty ()) {
2489
2504
if (warn) {
@@ -2891,7 +2906,7 @@ bool LoadObjWithCallback(std::istream &inStream, const callback_t &callback,
2891
2906
token += 7 ;
2892
2907
2893
2908
std::vector<std::string> filenames;
2894
- SplitString (std::string (token), ' ' , filenames);
2909
+ SplitString (std::string (token), ' ' , ' \\ ' , filenames);
2895
2910
2896
2911
if (filenames.empty ()) {
2897
2912
if (warn) {
0 commit comments