Chameleon Applications

Chameleon Applications Svn Source Tree

Root/branches/ErmaC/ChameleonPrefPane/Sources/KernOptionsParser.cpp

1/*
2 * KernOptionsParser.cpp
3 * ChameleonPrefPane
4 *
5 * Created by Rekursor on 1/23/10.
6 */
7
8#include "KernOptionsParser.h"
9#include "string_util.h"
10
11bool KernOptionsParser::parseOptions(const char* options)
12{
13_options = options ? trim(options) : "";
14std::string token, temp=_options;
15
16// first remove spaces around '=' to simplify parsing
17std::string::size_type found = std::string::npos;
18while ((found=_options.find(" =")) != std::string::npos) _options.replace(found, 3,"=");
19while ((found=_options.find("= ")) != std::string::npos) _options.replace(found, 3,"=");
20
21// then tokenize the string
22_optionsList = tokenize(_options);
23
24return true;
25}
26
27static const std::string sEmpty="";
28
29// get the corresponding kern option "xxxx=yyyy"
30const std::string& KernOptionsParser::stringFromKey(const std::string& key) const
31{
32for (std::list<std::string>::const_iterator it=_optionsList.begin(); it!=_optionsList.end(); it++)
33if (it->find(key)!=std::string::npos) return *it;
34
35return sEmpty;
36}
37
38// get the left member of kern option "xxxx=yyyy"
39const std::string& KernOptionsParser::leftMember(const std::string& expression) const
40{
41static std::string sLeft;
42std::string::size_type pos = expression.find('=');
43
44if (pos!=std::string::npos)
45return (sLeft = expression.substr(0, pos));
46return expression;
47}
48
49// get the right member of kern option "xxxx=yyyy"
50const std::string& KernOptionsParser::rightMember(const std::string& expression) const
51{
52static std::string sLeft;
53std::string::size_type pos = expression.find('=');
54
55if (pos!=std::string::npos)
56return (sLeft = expression.substr(pos+1));
57return expression;
58}
59// remove a flag in the string
60void KernOptionsParser::removeFlag(const std::string& flag)
61{
62std::string::size_type found = _options.find(flag);
63if (found==std::string::npos) return;
64_options.erase(found, found+flag.length());
65_options = trim(_options);
66}
67
68// remove a flag in the string
69void KernOptionsParser::addFlag(const std::string& flag)
70{
71std::string::size_type found = _options.find(flag);
72if (found!=std::string::npos) return;
73_options = " " + _options;
74_options = flag + _options;
75_options = trim(_options);
76}
77

Archive Download this file

Revision: 396