std::string CommandLine::GetSwitchValueASCII( const std::string& switch_string) const { StringType value = GetSwitchValueNative(switch_string); if(!IsStringASCII(value)) { LOG(WARNING) << "Value of --" << switch_string << " must be ASCII."; return ""; } return WideToASCII(value); }
std::string CommandLine::GetSwitchValueASCII( const std::string& switch_string) const { StringType value = GetSwitchValueNative(switch_string); //if (!IsStringASCII(value)) { // DLOG(WARNING) << "Value of switch (" << switch_string << ") must be ASCII."; // return std::string(); //} #if defined(OS_WIN) return WideToASCII(value); #else return value; #endif }
std::string GenerateGUID() { GUID guid; auto rv = CoCreateGuid(&guid); assert(SUCCEEDED(rv)); if (!SUCCEEDED(rv)) { return std::string(); } const int kGUIDStrSize = 40; std::array<wchar_t, kGUIDStrSize> guid_str; int count_written = StringFromGUID2(guid, guid_str.data(), kGUIDStrSize); // Since GUID contains ASCII-only characters, it is safe to do this conversion. // Strips off { and }. return count_written ? WideToASCII(WStringView(guid_str.data() + 1, count_written - 3)) : std::string(); }
bool CommandLine::IsSwitch(const StringType& parameter_string, std::string* switch_string, StringType* switch_value) { switch_string->clear(); switch_value->clear(); for(size_t i=0; i<arraysize(kSwitchPrefixes); ++i) { StringType prefix(kSwitchPrefixes[i]); if(parameter_string.find(prefix) != 0) { continue; } const size_t switch_start = prefix.length(); const size_t equals_position = parameter_string.find( kSwitchValueSeparator, switch_start); StringType switch_native; if(equals_position == StringType::npos) { switch_native = parameter_string.substr(switch_start); } else { switch_native = parameter_string.substr( switch_start, equals_position-switch_start); *switch_value = parameter_string.substr(equals_position+1); } *switch_string = WideToASCII(switch_native); Lowercase(switch_string); return true; } return false; }