diff options
Diffstat (limited to 'src/lib/server/Config.cpp')
| -rw-r--r-- | src/lib/server/Config.cpp | 349 |
1 files changed, 150 insertions, 199 deletions
diff --git a/src/lib/server/Config.cpp b/src/lib/server/Config.cpp index 3cf60a5..a47a391 100644 --- a/src/lib/server/Config.cpp +++ b/src/lib/server/Config.cpp @@ -48,7 +48,7 @@ Config::~Config() } bool -Config::addScreen(const String& name) +Config::addScreen(const std::string& name) { // alias name must not exist if (m_nameToCanonicalName.find(name) != m_nameToCanonicalName.end()) { @@ -64,12 +64,10 @@ Config::addScreen(const String& name) return true; } -bool -Config::renameScreen(const String& oldName, - const String& newName) +bool Config::renameScreen(const std::string& oldName, const std::string& newName) { // get canonical name and find cell - String oldCanonical = getCanonicalName(oldName); + std::string oldCanonical = getCanonicalName(oldName); CellMap::iterator index = m_map.find(oldCanonical); if (index == m_map.end()) { return false; @@ -111,11 +109,10 @@ Config::renameScreen(const String& oldName, return true; } -void -Config::removeScreen(const String& name) +void Config::removeScreen(const std::string& name) { // get canonical name and find cell - String canonical = getCanonicalName(name); + std::string canonical = getCanonicalName(name); CellMap::iterator index = m_map.find(canonical); if (index == m_map.end()) { return; @@ -149,8 +146,7 @@ Config::removeAllScreens() m_nameToCanonicalName.clear(); } -bool -Config::addAlias(const String& canonical, const String& alias) +bool Config::addAlias(const std::string& canonical, const std::string& alias) { // alias name must not exist if (m_nameToCanonicalName.find(alias) != m_nameToCanonicalName.end()) { @@ -168,8 +164,7 @@ Config::addAlias(const String& canonical, const String& alias) return true; } -bool -Config::removeAlias(const String& alias) +bool Config::removeAlias(const std::string& alias) { // must not be a canonical name if (m_map.find(alias) != m_map.end()) { @@ -188,8 +183,7 @@ Config::removeAlias(const String& alias) return true; } -bool -Config::removeAliases(const String& canonical) +bool Config::removeAliases(const std::string& canonical) { // must be a canonical name if (m_map.find(canonical) == m_map.end()) { @@ -224,12 +218,9 @@ Config::removeAllAliases() } } -bool -Config::connect(const String& srcName, - EDirection srcSide, - float srcStart, float srcEnd, - const String& dstName, - float dstStart, float dstEnd) +bool Config::connect(const std::string& srcName, EDirection srcSide, + float srcStart, float srcEnd, const std::string& dstName, + float dstStart, float dstEnd) { assert(srcSide >= kFirstDirection && srcSide <= kLastDirection); @@ -245,8 +236,7 @@ Config::connect(const String& srcName, return index->second.add(srcEdge, dstEdge); } -bool -Config::disconnect(const String& srcName, EDirection srcSide) +bool Config::disconnect(const std::string& srcName, EDirection srcSide) { assert(srcSide >= kFirstDirection && srcSide <= kLastDirection); @@ -262,8 +252,7 @@ Config::disconnect(const String& srcName, EDirection srcSide) return true; } -bool -Config::disconnect(const String& srcName, EDirection srcSide, float position) +bool Config::disconnect(const std::string& srcName, EDirection srcSide, float position) { assert(srcSide >= kFirstDirection && srcSide <= kLastDirection); @@ -285,8 +274,7 @@ Config::setBarrierAddress(const NetworkAddress& addr) m_barrierAddress = addr; } -bool -Config::addOption(const String& name, OptionID option, OptionValue value) +bool Config::addOption(const std::string& name, OptionID option, OptionValue value) { // find options ScreenOptions* options = NULL; @@ -308,8 +296,7 @@ Config::addOption(const String& name, OptionID option, OptionValue value) return true; } -bool -Config::removeOption(const String& name, OptionID option) +bool Config::removeOption(const std::string& name, OptionID option) { // find options ScreenOptions* options = NULL; @@ -331,8 +318,7 @@ Config::removeOption(const String& name, OptionID option) return true; } -bool -Config::removeOptions(const String& name) +bool Config::removeOptions(const std::string& name) { // find options ScreenOptions* options = NULL; @@ -354,8 +340,7 @@ Config::removeOptions(const String& name) return true; } -bool -Config::isValidScreenName(const String& name) const +bool Config::isValidScreenName(const std::string& name) const { // name is valid if matches validname // name ::= [_A-Za-z0-9] | [_A-Za-z0-9][-_A-Za-z0-9]*[_A-Za-z0-9] @@ -370,7 +355,7 @@ Config::isValidScreenName(const String& name) const } // check each dot separated part - String::size_type b = 0; + std::string::size_type b = 0; for (;;) { // accept trailing . if (b == name.size()) { @@ -378,8 +363,8 @@ Config::isValidScreenName(const String& name) const } // find end of part - String::size_type e = name.find('.', b); - if (e == String::npos) { + std::string::size_type e = name.find('.', b); + if (e == std::string::npos) { e = name.size(); } @@ -395,7 +380,7 @@ Config::isValidScreenName(const String& name) const } // check interior characters - for (String::size_type i = b; i < e; ++i) { + for (std::string::size_type i = b; i < e; ++i) { if (!isalnum(name[i]) && name[i] != '_' && name[i] != '-') { return false; } @@ -437,40 +422,38 @@ Config::endAll() const } bool -Config::isScreen(const String& name) const +Config::isScreen(const std::string& name) const { return (m_nameToCanonicalName.count(name) > 0); } bool -Config::isCanonicalName(const String& name) const +Config::isCanonicalName(const std::string& name) const { return (!name.empty() && CaselessCmp::equal(getCanonicalName(name), name)); } -String -Config::getCanonicalName(const String& name) const +std::string Config::getCanonicalName(const std::string& name) const { NameMap::const_iterator index = m_nameToCanonicalName.find(name); if (index == m_nameToCanonicalName.end()) { - return String(); + return std::string(); } else { return index->second; } } -String -Config::getNeighbor(const String& srcName, EDirection srcSide, - float position, float* positionOut) const +std::string Config::getNeighbor(const std::string& srcName, EDirection srcSide, + float position, float* positionOut) const { assert(srcSide >= kFirstDirection && srcSide <= kLastDirection); // find source cell CellMap::const_iterator index = m_map.find(getCanonicalName(srcName)); if (index == m_map.end()) { - return String(); + return std::string(); } // find edge @@ -491,15 +474,13 @@ Config::getNeighbor(const String& srcName, EDirection srcSide, } } -bool -Config::hasNeighbor(const String& srcName, EDirection srcSide) const +bool Config::hasNeighbor(const std::string& srcName, EDirection srcSide) const { return hasNeighbor(srcName, srcSide, 0.0f, 1.0f); } -bool -Config::hasNeighbor(const String& srcName, EDirection srcSide, - float start, float end) const +bool Config::hasNeighbor(const std::string& srcName, EDirection srcSide, + float start, float end) const { assert(srcSide >= kFirstDirection && srcSide <= kLastDirection); @@ -512,16 +493,14 @@ Config::hasNeighbor(const String& srcName, EDirection srcSide, return index->second.overlaps(CellEdge(srcSide, Interval(start, end))); } -Config::link_const_iterator -Config::beginNeighbor(const String& srcName) const +Config::link_const_iterator Config::beginNeighbor(const std::string& srcName) const { CellMap::const_iterator index = m_map.find(getCanonicalName(srcName)); assert(index != m_map.end()); return index->second.begin(); } -Config::link_const_iterator -Config::endNeighbor(const String& srcName) const +Config::link_const_iterator Config::endNeighbor(const std::string& srcName) const { CellMap::const_iterator index = m_map.find(getCanonicalName(srcName)); assert(index != m_map.end()); @@ -534,8 +513,7 @@ Config::getBarrierAddress() const return m_barrierAddress; } -const Config::ScreenOptions* -Config::getOptions(const String& name) const +const Config::ScreenOptions* Config::getOptions(const std::string& name) const { // find options const ScreenOptions* options = NULL; @@ -641,8 +619,7 @@ Config::getInputFilter() return &m_inputFilter; } -String -Config::formatInterval(const Interval& x) +std::string Config::formatInterval(const Interval& x) { if (x.first == 0.0f && x.second == 1.0f) { return ""; @@ -660,7 +637,7 @@ Config::readSection(ConfigReadContext& s) static const char s_links[] = "links"; static const char s_aliases[] = "aliases"; - String line; + std::string line; if (!s.readLine(line)) { // no more sections return; @@ -672,13 +649,13 @@ Config::readSection(ConfigReadContext& s) } // get section name - String::size_type i = line.find_first_not_of(" \t", sizeof(s_section) - 1); - if (i == String::npos) { + std::string::size_type i = line.find_first_not_of(" \t", sizeof(s_section) - 1); + if (i == std::string::npos) { throw XConfigRead(s, "section name is missing"); } - String name = line.substr(i); + std::string name = line.substr(i); i = name.find_first_of(" \t"); - if (i != String::npos) { + if (i != std::string::npos) { throw XConfigRead(s, "unexpected data after section name"); } @@ -703,7 +680,7 @@ Config::readSection(ConfigReadContext& s) void Config::readSectionOptions(ConfigReadContext& s) { - String line; + std::string line; while (s.readLine(line)) { // check for end of section if (line == "end") { @@ -714,8 +691,8 @@ Config::readSectionOptions(ConfigReadContext& s) // nameAndArgs := <name>[(arg[,...])] // values := valueAndArgs[,valueAndArgs]... // valueAndArgs := <value>[(arg[,...])] - String::size_type i = 0; - String name, value; + std::string::size_type i = 0; + std::string name, value; ConfigReadContext::ArgList nameArgs, valueArgs; s.parseNameWithArgs("name", line, "=", i, name, nameArgs); ++i; @@ -728,8 +705,7 @@ Config::readSectionOptions(ConfigReadContext& s) m_barrierAddress.resolve(); } catch (XSocketAddress& e) { - throw XConfigRead(s, - String("invalid address argument ") + e.what()); + throw XConfigRead(s, std::string("invalid address argument ") + e.what()); } } else if (name == "heartbeat") { @@ -799,7 +775,7 @@ Config::readSectionOptions(ConfigReadContext& s) if (i < line.length() && line[i] == ';') { // allow trailing ';' i = line.find_first_not_of(" \t", i + 1); - if (i == String::npos) { + if (i == std::string::npos) { i = line.length(); } else { @@ -825,9 +801,9 @@ Config::readSectionOptions(ConfigReadContext& s) void Config::readSectionScreens(ConfigReadContext& s) { - String line; - String screen; - while (s.readLine(line)) { + std::string line; + std::string screen; + while (s.readLine(line)) { // check for end of section if (line == "end") { return; @@ -853,21 +829,21 @@ Config::readSectionScreens(ConfigReadContext& s) } else { // parse argument: `<name>=<value>' - String::size_type i = line.find_first_of(" \t="); + std::string::size_type i = line.find_first_of(" \t="); if (i == 0) { throw XConfigRead(s, "missing argument name"); } - if (i == String::npos) { + if (i == std::string::npos) { throw XConfigRead(s, "missing ="); } - String name = line.substr(0, i); + std::string name = line.substr(0, i); i = line.find_first_not_of(" \t", i); - if (i == String::npos || line[i] != '=') { + if (i == std::string::npos || line[i] != '=') { throw XConfigRead(s, "missing ="); } i = line.find_first_not_of(" \t", i + 1); - String value; - if (i != String::npos) { + std::string value; + if (i != std::string::npos) { value = line.substr(i); } @@ -936,8 +912,8 @@ Config::readSectionScreens(ConfigReadContext& s) void Config::readSectionLinks(ConfigReadContext& s) { - String line; - String screen; + std::string line; + std::string screen; while (s.readLine(line)) { // check for end of section if (line == "end") { @@ -965,8 +941,8 @@ Config::readSectionLinks(ConfigReadContext& s) // the stuff in brackets is optional. interval values must be // in the range [0,100] and start < end. if not given the // interval is taken to be (0,100). - String::size_type i = 0; - String side, dstScreen, srcArgString, dstArgString; + std::string::size_type i = 0; + std::string side, dstScreen, srcArgString, dstArgString; ConfigReadContext::ArgList srcArgs, dstArgs; s.parseNameWithArgs("link", line, "=", i, side, srcArgs); ++i; @@ -1009,8 +985,8 @@ Config::readSectionLinks(ConfigReadContext& s) void Config::readSectionAliases(ConfigReadContext& s) { - String line; - String screen; + std::string line; + std::string screen; while (s.readLine(line)) { // check for end of section if (line == "end") { @@ -1049,9 +1025,8 @@ Config::readSectionAliases(ConfigReadContext& s) } -InputFilter::Condition* -Config::parseCondition(ConfigReadContext& s, - const String& name, const std::vector<String>& args) +InputFilter::Condition* Config::parseCondition(ConfigReadContext& s, const std::string& name, + const std::vector<std::string>& args) { if (name == "keystroke") { if (args.size() != 1) { @@ -1078,7 +1053,7 @@ Config::parseCondition(ConfigReadContext& s, throw XConfigRead(s, "syntax for condition: connect([screen])"); } - String screen = args[0]; + std::string screen = args[0]; if (isScreen(screen)) { screen = getCanonicalName(screen); } @@ -1092,10 +1067,9 @@ Config::parseCondition(ConfigReadContext& s, throw XConfigRead(s, "unknown argument \"%{1}\"", name); } -void -Config::parseAction(ConfigReadContext& s, - const String& name, const std::vector<String>& args, - InputFilter::Rule& rule, bool activate) +void Config::parseAction(ConfigReadContext& s, const std::string& name, + const std::vector<std::string>& args, + InputFilter::Rule& rule, bool activate) { InputFilter::Action* action; @@ -1109,7 +1083,7 @@ Config::parseAction(ConfigReadContext& s, keyInfo = s.parseKeystroke(args[0]); } else { - std::set<String> screens; + std::set<std::string> screens; parseScreens(s, args[1], screens); keyInfo = s.parseKeystroke(args[0], screens); } @@ -1171,7 +1145,7 @@ Config::parseAction(ConfigReadContext& s, throw XConfigRead(s, "syntax for action: switchToScreen(name)"); } - String screen = args[0]; + std::string screen = args[0]; if (isScreen(screen)) { screen = getCanonicalName(screen); } @@ -1182,6 +1156,10 @@ Config::parseAction(ConfigReadContext& s, action = new InputFilter::SwitchToScreenAction(m_events, screen); } + else if (name == "toggleScreen") { + action = new InputFilter::ToggleScreenAction(m_events); + } + else if (name == "switchInDirection") { if (args.size() != 1) { throw XConfigRead(s, "syntax for action: switchInDirection(<left|right|up|down>)"); @@ -1258,7 +1236,7 @@ Config::parseAction(ConfigReadContext& s, } } - std::set<String> screens; + std::set<std::string> screens; if (args.size() >= 2) { parseScreens(s, args[1], screens); } @@ -1273,22 +1251,21 @@ Config::parseAction(ConfigReadContext& s, rule.adoptAction(action, activate); } -void -Config::parseScreens(ConfigReadContext& c, - const String& s, std::set<String>& screens) const +void Config::parseScreens(ConfigReadContext& c, const std::string& s, + std::set<std::string>& screens) const { screens.clear(); - String::size_type i = 0; + std::string::size_type i = 0; while (i < s.size()) { // find end of next screen name - String::size_type j = s.find(':', i); - if (j == String::npos) { + std::string::size_type j = s.find(':', i); + if (j == std::string::npos) { j = s.size(); } // extract name - String rawName; + std::string rawName; i = s.find_first_not_of(" \t", i); if (i < j) { rawName = s.substr(i, s.find_last_not_of(" \t", j - 1) - i + 1); @@ -1299,7 +1276,7 @@ Config::parseScreens(ConfigReadContext& c, screens.insert("*"); } else if (!rawName.empty()) { - String name = getCanonicalName(rawName); + std::string name = getCanonicalName(rawName); if (name.empty()) { throw XConfigRead(c, "unknown screen name \"%{1}\"", rawName); } @@ -1386,8 +1363,7 @@ Config::getOptionName(OptionID id) return NULL; } -String -Config::getOptionValue(OptionID id, OptionValue value) +std::string Config::getOptionValue(OptionID id, OptionValue value) { if (id == kOptionHalfDuplexCapsLock || id == kOptionHalfDuplexNumLock || @@ -1463,17 +1439,16 @@ Config::getOptionValue(OptionID id, OptionValue value) // Config::Name // -Config::Name::Name(Config* config, const String& name) : +Config::Name::Name(Config* config, const std::string& name) : m_config(config), m_name(config->getCanonicalName(name)) { // do nothing } -bool -Config::Name::operator==(const String& name) const +bool Config::Name::operator==(const std::string& name) const { - String canonical = m_config->getCanonicalName(name); + std::string canonical = m_config->getCanonicalName(name); return CaselessCmp::equal(canonical, m_name); } @@ -1496,8 +1471,7 @@ Config::CellEdge::CellEdge(EDirection side, const Interval& interval) init("", side, interval); } -Config::CellEdge::CellEdge(const String& name, - EDirection side, const Interval& interval) +Config::CellEdge::CellEdge(const std::string& name, EDirection side, const Interval& interval) { assert(interval.first >= 0.0f); assert(interval.second <= 1.0f); @@ -1511,9 +1485,7 @@ Config::CellEdge::~CellEdge() // do nothing } -void -Config::CellEdge::init(const String& name, EDirection side, - const Interval& interval) +void Config::CellEdge::init(const std::string& name, EDirection side, const Interval& interval) { assert(side != kNoDirection); @@ -1528,14 +1500,12 @@ Config::CellEdge::getInterval() const return m_interval; } -void -Config::CellEdge::setName(const String& newName) +void Config::CellEdge::setName(const std::string& newName) { m_name = newName; } -String -Config::CellEdge::getName() const +std::string Config::CellEdge::getName() const { return m_name; } @@ -1662,8 +1632,7 @@ Config::Cell::remove(const Name& name) } } -void -Config::Cell::rename(const Name& oldName, const String& newName) +void Config::Cell::rename(const Name& oldName, const std::string& newName) { for (EdgeLinks::iterator j = m_neighbors.begin(); j != m_neighbors.end(); ++j) { @@ -1789,8 +1758,7 @@ operator<<(std::ostream& s, const Config& config) option = options->begin(); option != options->end(); ++option) { const char* name = Config::getOptionName(option->first); - String value = Config::getOptionValue(option->first, - option->second); + std::string value = Config::getOptionValue(option->first, option->second); if (name != NULL && !value.empty()) { s << "\t\t" << name << " = " << value << std::endl; } @@ -1800,7 +1768,7 @@ operator<<(std::ostream& s, const Config& config) s << "end" << std::endl; // links section - String neighbor; + std::string neighbor; s << "section: links" << std::endl; for (Config::const_iterator screen = config.begin(); screen != config.end(); ++screen) { @@ -1821,8 +1789,7 @@ operator<<(std::ostream& s, const Config& config) // aliases section (if there are any) if (config.m_map.size() != config.m_nameToCanonicalName.size()) { // map canonical to alias - typedef std::multimap<String, String, - CaselessCmp> CMNameMap; + typedef std::multimap<std::string, std::string, CaselessCmp> CMNameMap; CMNameMap aliases; for (Config::NameMap::const_iterator index = config.m_nameToCanonicalName.begin(); @@ -1834,7 +1801,7 @@ operator<<(std::ostream& s, const Config& config) } // dump it - String screen; + std::string screen; s << "section: aliases" << std::endl; for (CMNameMap::const_iterator index = aliases.begin(); index != aliases.end(); ++index) { @@ -1855,8 +1822,7 @@ operator<<(std::ostream& s, const Config& config) option = options->begin(); option != options->end(); ++option) { const char* name = Config::getOptionName(option->first); - String value = Config::getOptionValue(option->first, - option->second); + std::string value = Config::getOptionValue(option->first, option->second); if (name != NULL && !value.empty()) { s << "\t" << name << " = " << value << std::endl; } @@ -1889,24 +1855,23 @@ ConfigReadContext::~ConfigReadContext() // do nothing } -bool -ConfigReadContext::readLine(String& line) +bool ConfigReadContext::readLine(std::string& line) { ++m_line; while (std::getline(m_stream, line)) { // strip leading whitespace - String::size_type i = line.find_first_not_of(" \t"); - if (i != String::npos) { - line.erase(0, i); + std::string::size_type i = line.find_first_not_of(" \t"); + if (i != std::string::npos) { + line.erase(0, i); } // strip comments and then trailing whitespace i = line.find('#'); - if (i != String::npos) { + if (i != std::string::npos) { line.erase(i); } i = line.find_last_not_of(" \r\t"); - if (i != String::npos) { + if (i != std::string::npos) { line.erase(i + 1); } @@ -1942,8 +1907,7 @@ ConfigReadContext::operator!() const return !m_stream; } -OptionValue -ConfigReadContext::parseBoolean(const String& arg) const +OptionValue ConfigReadContext::parseBoolean(const std::string& arg) const { if (CaselessCmp::equal(arg, "true")) { return static_cast<OptionValue>(true); @@ -1954,8 +1918,7 @@ ConfigReadContext::parseBoolean(const String& arg) const throw XConfigRead(*this, "invalid boolean argument \"%{1}\"", arg); } -OptionValue -ConfigReadContext::parseInt(const String& arg) const +OptionValue ConfigReadContext::parseInt(const std::string& arg) const { const char* s = arg.c_str(); char* end; @@ -1972,8 +1935,7 @@ ConfigReadContext::parseInt(const String& arg) const return value; } -OptionValue -ConfigReadContext::parseModifierKey(const String& arg) const +OptionValue ConfigReadContext::parseModifierKey(const std::string& arg) const { if (CaselessCmp::equal(arg, "shift")) { return static_cast<OptionValue>(kKeyModifierIDShift); @@ -1999,8 +1961,7 @@ ConfigReadContext::parseModifierKey(const String& arg) const throw XConfigRead(*this, "invalid argument \"%{1}\"", arg); } -OptionValue -ConfigReadContext::parseCorner(const String& arg) const +OptionValue ConfigReadContext::parseCorner(const std::string& arg) const { if (CaselessCmp::equal(arg, "left")) { return kTopLeftMask | kBottomLeftMask; @@ -2035,22 +1996,21 @@ ConfigReadContext::parseCorner(const String& arg) const throw XConfigRead(*this, "invalid argument \"%{1}\"", arg); } -OptionValue -ConfigReadContext::parseCorners(const String& args) const +OptionValue ConfigReadContext::parseCorners(const std::string& args) const { // find first token - String::size_type i = args.find_first_not_of(" \t", 0); - if (i == String::npos) { + std::string::size_type i = args.find_first_not_of(" \t", 0); + if (i == std::string::npos) { throw XConfigRead(*this, "missing corner argument"); } - String::size_type j = args.find_first_of(" \t", i); + std::string::size_type j = args.find_first_of(" \t", i); // parse first corner token OptionValue corners = parseCorner(args.substr(i, j - i)); // get +/- i = args.find_first_not_of(" \t", j); - while (i != String::npos) { + while (i != std::string::npos) { // parse +/- bool add; if (args[i] == '-') { @@ -2060,15 +2020,14 @@ ConfigReadContext::parseCorners(const String& args) const add = true; } else { - throw XConfigRead(*this, - "invalid corner operator \"%{1}\"", - String(args.c_str() + i, 1)); + throw XConfigRead(*this, "invalid corner operator \"%{1}\"", + std::string(args.c_str() + i, 1)); } // get next corner token i = args.find_first_not_of(" \t", i + 1); j = args.find_first_of(" \t", i); - if (i == String::npos) { + if (i == std::string::npos) { throw XConfigRead(*this, "missing corner argument"); } @@ -2114,21 +2073,19 @@ ConfigReadContext::parseInterval(const ArgList& args) const return Config::Interval(startValue / 100.0f, endValue / 100.0f); } -void -ConfigReadContext::parseNameWithArgs( - const String& type, const String& line, - const String& delim, String::size_type& index, - String& name, ArgList& args) const +void ConfigReadContext::parseNameWithArgs(const std::string& type, const std::string& line, + const std::string& delim, std::string::size_type& index, + std::string& name, ArgList& args) const { // skip leading whitespace - String::size_type i = line.find_first_not_of(" \t", index); - if (i == String::npos) { - throw XConfigRead(*this, String("missing ") + type); + std::string::size_type i = line.find_first_not_of(" \t", index); + if (i == std::string::npos) { + throw XConfigRead(*this, std::string("missing ") + type); } // find end of name - String::size_type j = line.find_first_of(" \t(" + delim, i); - if (j == String::npos) { + std::string::size_type j = line.find_first_of(" \t(" + delim, i); + if (j == std::string::npos) { j = line.length(); } @@ -2137,15 +2094,15 @@ ConfigReadContext::parseNameWithArgs( args.clear(); // is it okay to not find a delimiter? - bool needDelim = (!delim.empty() && delim.find('\n') == String::npos); + bool needDelim = (!delim.empty() && delim.find('\n') == std::string::npos); // skip whitespace i = line.find_first_not_of(" \t", j); - if (i == String::npos && needDelim) { + if (i == std::string::npos && needDelim) { // expected delimiter but didn't find it - throw XConfigRead(*this, String("missing ") + delim[0]); + throw XConfigRead(*this, std::string("missing ") + delim[0]); } - if (i == String::npos) { + if (i == std::string::npos) { // no arguments index = line.length(); return; @@ -2161,18 +2118,18 @@ ConfigReadContext::parseNameWithArgs( // parse arguments j = line.find_first_of(",)", i); - while (j != String::npos) { + while (j != std::string::npos) { // extract arg - String arg(line.substr(i, j - i)); + std::string arg(line.substr(i, j - i)); i = j; // trim whitespace j = arg.find_first_not_of(" \t"); - if (j != String::npos) { + if (j != std::string::npos) { arg.erase(0, j); } j = arg.find_last_not_of(" \t"); - if (j != String::npos) { + if (j != std::string::npos) { arg.erase(j + 1); } @@ -2192,7 +2149,7 @@ ConfigReadContext::parseNameWithArgs( } // verify ')' - if (j == String::npos) { + if (j == std::string::npos) { // expected ) throw XConfigRead(*this, "missing )"); } @@ -2202,17 +2159,17 @@ ConfigReadContext::parseNameWithArgs( // skip whitespace j = line.find_first_not_of(" \t", i); - if (j == String::npos && needDelim) { + if (j == std::string::npos && needDelim) { // expected delimiter but didn't find it - throw XConfigRead(*this, String("missing ") + delim[0]); + throw XConfigRead(*this, std::string("missing ") + delim[0]); } // verify delimiter - if (needDelim && delim.find(line[j]) == String::npos) { - throw XConfigRead(*this, String("expected ") + delim[0]); + if (needDelim && delim.find(line[j]) == std::string::npos) { + throw XConfigRead(*this, std::string("expected ") + delim[0]); } - if (j == String::npos) { + if (j == std::string::npos) { j = line.length(); } @@ -2220,17 +2177,15 @@ ConfigReadContext::parseNameWithArgs( return; } -IPlatformScreen::KeyInfo* -ConfigReadContext::parseKeystroke(const String& keystroke) const +IPlatformScreen::KeyInfo* ConfigReadContext::parseKeystroke(const std::string& keystroke) const { - return parseKeystroke(keystroke, std::set<String>()); + return parseKeystroke(keystroke, std::set<std::string>()); } -IPlatformScreen::KeyInfo* -ConfigReadContext::parseKeystroke(const String& keystroke, - const std::set<String>& screens) const +IPlatformScreen::KeyInfo* ConfigReadContext::parseKeystroke(const std::string& keystroke, + const std::set<std::string>& screens) const { - String s = keystroke; + std::string s = keystroke; KeyModifierMask mask; if (!barrier::KeyMap::parseModifiers(s, mask)) { @@ -2250,9 +2205,9 @@ ConfigReadContext::parseKeystroke(const String& keystroke, } IPlatformScreen::ButtonInfo* -ConfigReadContext::parseMouse(const String& mouse) const +ConfigReadContext::parseMouse(const std::string& mouse) const { - String s = mouse; + std::string s = mouse; KeyModifierMask mask; if (!barrier::KeyMap::parseModifiers(s, mask)) { @@ -2271,10 +2226,9 @@ ConfigReadContext::parseMouse(const String& mouse) const return IPlatformScreen::ButtonInfo::alloc(button, mask); } -KeyModifierMask -ConfigReadContext::parseModifier(const String& modifiers) const +KeyModifierMask ConfigReadContext::parseModifier(const std::string& modifiers) const { - String s = modifiers; + std::string s = modifiers; KeyModifierMask mask; if (!barrier::KeyMap::parseModifiers(s, mask)) { @@ -2288,10 +2242,9 @@ ConfigReadContext::parseModifier(const String& modifiers) const return mask; } -String -ConfigReadContext::concatArgs(const ArgList& args) +std::string ConfigReadContext::concatArgs(const ArgList& args) { - String s("("); + std::string s("("); for (size_t i = 0; i < args.size(); ++i) { if (i != 0) { s += ","; @@ -2307,29 +2260,27 @@ ConfigReadContext::concatArgs(const ArgList& args) // Config I/O exceptions // -XConfigRead::XConfigRead(const ConfigReadContext& context, - const String& error) : +XConfigRead::XConfigRead(const ConfigReadContext& context, const std::string& error) : m_error(barrier::string::sprintf("line %d: %s", context.getLineNumber(), error.c_str())) { // do nothing } -XConfigRead::XConfigRead(const ConfigReadContext& context, - const char* errorFmt, const String& arg) : +XConfigRead::XConfigRead(const ConfigReadContext& context, const char* errorFmt, + const std::string& arg) : m_error(barrier::string::sprintf("line %d: ", context.getLineNumber()) + barrier::string::format(errorFmt, arg.c_str())) { // do nothing } -XConfigRead::~XConfigRead() _NOEXCEPT +XConfigRead::~XConfigRead() noexcept { // do nothing } -String -XConfigRead::getWhat() const throw() +std::string XConfigRead::getWhat() const noexcept { return format("XConfigRead", "read error: %{1}", m_error.c_str()); } |
