History

windows file path expansion update

Ge Wang committed 3 years ago

Commit bb784ef1 parent 5d2e58a1 file · +12 −9Browse files

Showing the changes to src/core/util_string.cpp (1 of 1 file). Show all

Unified · Split

src/core/util_string.cpp+12−9
@@ -502,15 +502,16 @@ std::string expandFilePathWindows( const string & path ) · 501 unmodified lines
502502 {
503503 // expansion
504504 string exp;
505−
506505 // tokens
507506 vector<string> tokens;
507+
508+ // trim of white spaces
509+ string thePath = trim( path );
510+
508511 // tokenize
509− tokenize( path, tokens, "%" );
512+ tokenize( thePath, tokens, "%" );
510513 // 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] == '%');
514515 // loop
515516 for( t_CKINT i = 0; i < tokens.size(); i++ )
516517 {
@@ -520,9 +521,11 @@ std::string expandFilePathWindows( const string & path ) · 3 unmodified lines
520521 {
521522 // get environment variable
522523 char * v = getenv( tokens[i].c_str() );
524+ // if got something back
523525 if( v ) exp += v;
524526 else
525527 {
528+ // error message
526529 EM_log( CK_LOG_SYSTEM, "ERROR expanding %%%s%% in path...", tokens[i].c_str() );
527530 // reset
528531 exp = "";
@@ -530,12 +533,12 @@ std::string expandFilePathWindows( const string & path ) · 1 unmodified line
530533 break;
531534 }
532535 }
533− // flip
536+ // flip | HACK: path does not contain immediately consecutive env-vars
534537 expand = !expand;
535538 }
536539
537540 // if exp still empty, no change
538− if( exp == "" ) exp = path;
541+ if( exp == "" ) exp = thePath;
539542
540543 // done
541544 return exp;
@@ -922,7 +925,7 @@ void tokenize( const std::string & str, std::vector<string> & tokens, const std: · 380 unmodified lines
922925 // substr len
923926 t_CKINT slen = i-start;
924927 // check
925− if( len > 0 )
928+ if( slen > 0 )
926929 {
927930 // push back the substr
928931 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
935938 // get the remainder
936939 t_CKINT slen = len-start;
937940 // check
938− if( len > 0 )
941+ if( slen > 0 )
939942 {
940943 // push back the substr
941944 tokens.push_back( str.substr( start, slen ) );

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t