History

windows file path expansion update

Ge Wang committed 3 years ago

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

Unified · Split

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