Index: trunk/ChameleonPrefPane/Sources/string_util.h =================================================================== --- trunk/ChameleonPrefPane/Sources/string_util.h (revision 452) +++ trunk/ChameleonPrefPane/Sources/string_util.h (revision 453) @@ -86,10 +86,20 @@ { std::string str = source; std::string::size_type pos = source.find_first_of(substr); - return pos!=std::string::npos ? str.erase(source.find_first_of(substr) ) : str; + return pos!=std::string::npos ? str.erase(pos) : str; } /** + * return the right portion of the string until substr sep is found + */ +inline std::string string_right( const std::string& source, const std::string& substr = " ") +{ + std::string str = source; + std::string::size_type pos = source.find_last_of(substr); + return pos!=std::string::npos ? str.erase(0, pos+1) : str; +} + +/** * return the left portion of the string until substr sep is found */ inline std::string string_dir_from(const std::string& source) Index: trunk/ChameleonPrefPane/Sources/PropertyList.cpp =================================================================== --- trunk/ChameleonPrefPane/Sources/PropertyList.cpp (revision 452) +++ trunk/ChameleonPrefPane/Sources/PropertyList.cpp (revision 453) @@ -25,7 +25,7 @@ char * buf = strdup(args); char lastPriorityDelim=' '; - printf("Parsing <%s>\n", args); + // printf("Parsing <%s>\n", args); int k=0; for (int i=0; i< strlen(args); i++) Index: trunk/ChameleonPrefPane/Sources/CenterTextFieldCell.mm =================================================================== --- trunk/ChameleonPrefPane/Sources/CenterTextFieldCell.mm (revision 452) +++ trunk/ChameleonPrefPane/Sources/CenterTextFieldCell.mm (revision 453) @@ -20,5 +20,3 @@ } @end - - Index: trunk/ChameleonPrefPane/Sources/KernOptionsParser.h =================================================================== --- trunk/ChameleonPrefPane/Sources/KernOptionsParser.h (revision 452) +++ trunk/ChameleonPrefPane/Sources/KernOptionsParser.h (revision 453) @@ -6,6 +6,7 @@ */ #include #include +#include "string_util.h" class KernOptionsParser { @@ -19,10 +20,16 @@ const std::string& stringFromKey(const std::string& key) const; // get the left member of kern option "xxxx=yyyy" - const std::string& leftMember(const std::string& expression) const; + inline std::string leftMember(const std::string& expression) const + { + return string_left(expression, "="); + } // get the right member of kern option "xxxx=yyyy" - const std::string& rightMember(const std::string& expression) const; + inline std::string rightMember(const std::string& expression) const + { + return string_right(expression, "="); + } // add / remove a kernel Flags in the string void addFlag(const std::string& flag); Index: trunk/ChameleonPrefPane/Sources/KernOptionsParser.cpp =================================================================== --- trunk/ChameleonPrefPane/Sources/KernOptionsParser.cpp (revision 452) +++ trunk/ChameleonPrefPane/Sources/KernOptionsParser.cpp (revision 453) @@ -15,8 +15,8 @@ // first remove spaces around '=' to simplify parsing std::string::size_type found = std::string::npos; - while ((found=_options.find(" =")) != std::string::npos) _options.replace(found, 3,"="); - while ((found=_options.find("= ")) != std::string::npos) _options.replace(found, 3,"="); + while ((found=_options.find(" =")) != std::string::npos) _options.replace(found, 2,"="); + while ((found=_options.find("= ")) != std::string::npos) _options.replace(found, 2,"="); // then tokenize the string _optionsList = tokenize(_options); @@ -35,34 +35,13 @@ return sEmpty; } -// get the left member of kern option "xxxx=yyyy" -const std::string& KernOptionsParser::leftMember(const std::string& expression) const -{ - static std::string sLeft; - std::string::size_type pos = expression.find('='); - - if (pos!=std::string::npos) - return (sLeft = expression.substr(0, pos)); - return expression; -} - -// get the right member of kern option "xxxx=yyyy" -const std::string& KernOptionsParser::rightMember(const std::string& expression) const -{ - static std::string sLeft; - std::string::size_type pos = expression.find('='); - - if (pos!=std::string::npos) - return (sLeft = expression.substr(pos+1)); - return expression; -} // remove a flag in the string void KernOptionsParser::removeFlag(const std::string& flag) { if (flag.length()==0) return; // not a flag, bye std::string::size_type pos, l = _options.length(); if (l==0) return; // empty options nothing to do - std::string f = string_left(flag, "="); + std::string f = leftMember(flag); std::string::size_type found = _options.find(f); if (found==std::string::npos) return; // find the end of the flag @@ -81,7 +60,7 @@ std::string::size_type found = _options.find(key); if (found!=std::string::npos) removeFlag(key); - _options = " " + _options; + _options = " " + _options; _options = flag + _options; _options = trim(_options); } Index: trunk/ChameleonPrefPane/test_util/test_util.mm =================================================================== --- trunk/ChameleonPrefPane/test_util/test_util.mm (revision 452) +++ trunk/ChameleonPrefPane/test_util/test_util.mm (revision 453) @@ -11,6 +11,9 @@ #import "PartitionInfoManager.h" #import "SmbiosExtractor.h" #import "ShellProcess.h" +#include "string_util.h" +#include +#include void testDiskInfoWith(NSString * bsd) { @@ -73,7 +76,21 @@ testDiskInfoWith(@"disk0s2"); testDiskInfoWith(@"disk0s3"); #endif - - [pool drain]; + fprintf(stderr, "String Test\n"); + std::string options = "-v darkwake ab= a=0 =abc -f"; + fprintf(stderr, "options = %s\n", options.c_str() ); + std::list l = tokenize(options, " "); + std::list::const_iterator it = l.begin(); + for (; it != l.end(); it++) + { + std::string s = *it; + std::cerr << "token: " << s + << ", left: " << string_left(s, "=") + << ", right: " << string_right(s, "=") + << ", trim: " << trim(s) + << std::endl; + } + + [pool drain]; return 0; } Index: trunk/ChameleonPrefPane/test_util/test_util.xcodeproj/project.pbxproj =================================================================== --- trunk/ChameleonPrefPane/test_util/test_util.xcodeproj/project.pbxproj (revision 452) +++ trunk/ChameleonPrefPane/test_util/test_util.xcodeproj/project.pbxproj (revision 453) @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 45; + objectVersion = 46; objects = { /* Begin PBXBuildFile section */ @@ -199,8 +199,11 @@ /* Begin PBXProject section */ 08FB7793FE84155DC02AAC07 /* Project object */ = { isa = PBXProject; + attributes = { + LastUpgradeCheck = 0420; + }; buildConfigurationList = 1DEB927808733DD40010E9CD /* Build configuration list for PBXProject "test_util" */; - compatibilityVersion = "Xcode 3.1"; + compatibilityVersion = "Xcode 3.2"; developmentRegion = English; hasScannedForEncodings = 1; knownRegions = ( @@ -245,7 +248,6 @@ ALWAYS_SEARCH_USER_PATHS = NO; COPY_PHASE_STRIP = NO; GCC_DYNAMIC_NO_PIC = NO; - GCC_ENABLE_FIX_AND_CONTINUE = YES; GCC_MODEL_TUNING = G5; GCC_OPTIMIZATION_LEVEL = 0; GCC_PRECOMPILE_PREFIX_HEADER = YES; @@ -278,7 +280,6 @@ GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; ONLY_ACTIVE_ARCH = YES; - PREBINDING = NO; SDKROOT = macosx10.6; }; name = Debug; @@ -291,7 +292,6 @@ GCC_ENABLE_OBJC_GC = supported; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; - PREBINDING = NO; SDKROOT = macosx10.6; }; name = Release;