Showing the changes to src/core/util_string.cpp (1 of 1 file). Show all
Unified · Split
| @@ -502,15 +502,16 @@ std::string expandFilePathWindows( const string & path ) · 501 unmodified lines | ||
| 502 | 502 | { |
| 503 | 503 | // expansion |
| 504 | 504 | string exp; |
| 505 | − | |
| 506 | 505 | // tokens |
| 507 | 506 | vector<string> tokens; |
| 507 | + | |
| 508 | + // trim of white spaces | |
| 509 | + string thePath = trim( path ); | |
| 510 | + | |
| 508 | 511 | // tokenize |
| 509 | − tokenize( path, tokens, "%" ); | |
| 512 | + tokenize( thePath, tokens, "%" ); | |
| 510 | 513 | // every other one is an environment variable |
| 511 | − // HACK: this assumes 1) path does not begin with an env-var | |
| 512 | − // and 2) path does not contain immediately consecutive env-vars | |
| 513 | − t_CKBOOL expand = FALSE; | |
| 514 | + t_CKBOOL expand = (thePath.length() && thePath[0] == '%'); | |
| 514 | 515 | // loop |
| 515 | 516 | for( t_CKINT i = 0; i < tokens.size(); i++ ) |
| 516 | 517 | { |
| @@ -520,9 +521,11 @@ std::string expandFilePathWindows( const string & path ) · 3 unmodified lines | ||
| 520 | 521 | { |
| 521 | 522 | // get environment variable |
| 522 | 523 | char * v = getenv( tokens[i].c_str() ); |
| 524 | + // if got something back | |
| 523 | 525 | if( v ) exp += v; |
| 524 | 526 | else |
| 525 | 527 | { |
| 528 | + // error message | |
| 526 | 529 | EM_log( CK_LOG_SYSTEM, "ERROR expanding %%%s%% in path...", tokens[i].c_str() ); |
| 527 | 530 | // reset |
| 528 | 531 | exp = ""; |
| @@ -530,12 +533,12 @@ std::string expandFilePathWindows( const string & path ) · 1 unmodified line | ||
| 530 | 533 | break; |
| 531 | 534 | } |
| 532 | 535 | } |
| 533 | − // flip | |
| 536 | + // flip | HACK: path does not contain immediately consecutive env-vars | |
| 534 | 537 | expand = !expand; |
| 535 | 538 | } |
| 536 | 539 | |
| 537 | 540 | // if exp still empty, no change |
| 538 | − if( exp == "" ) exp = path; | |
| 541 | + if( exp == "" ) exp = thePath; | |
| 539 | 542 | |
| 540 | 543 | // done |
| 541 | 544 | return exp; |
| @@ -922,7 +925,7 @@ void tokenize( const std::string & str, std::vector<string> & tokens, const std: · 380 unmodified lines | ||
| 922 | 925 | // substr len |
| 923 | 926 | t_CKINT slen = i-start; |
| 924 | 927 | // check |
| 925 | − if( len > 0 ) | |
| 928 | + if( slen > 0 ) | |
| 926 | 929 | { |
| 927 | 930 | // push back the substr |
| 928 | 931 | tokens.push_back( str.substr( start, slen ) ); |
| @@ -935,7 +938,7 @@ void tokenize( const std::string & str, std::vector<string> & tokens, const std: · 6 unmodified lines | ||
| 935 | 938 | // get the remainder |
| 936 | 939 | t_CKINT slen = len-start; |
| 937 | 940 | // check |
| 938 | − if( len > 0 ) | |
| 941 | + if( slen > 0 ) | |
| 939 | 942 | { |
| 940 | 943 | // push back the substr |
| 941 | 944 | tokens.push_back( str.substr( start, slen ) ); |