OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/string_util.h" | 5 #include "base/string_util.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #include <ctype.h> | 9 #include <ctype.h> |
10 #include <errno.h> | 10 #include <errno.h> |
(...skipping 1122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1133 std::vector<std::wstring>* r) { | 1133 std::vector<std::wstring>* r) { |
1134 SplitStringT(str, s, false, r); | 1134 SplitStringT(str, s, false, r); |
1135 } | 1135 } |
1136 | 1136 |
1137 void SplitStringDontTrim(const std::string& str, | 1137 void SplitStringDontTrim(const std::string& str, |
1138 char s, | 1138 char s, |
1139 std::vector<std::string>* r) { | 1139 std::vector<std::string>* r) { |
1140 SplitStringT(str, s, false, r); | 1140 SplitStringT(str, s, false, r); |
1141 } | 1141 } |
1142 | 1142 |
| 1143 template<typename STR> |
| 1144 static STR JoinStringT(const std::vector<STR>& parts, |
| 1145 typename STR::value_type sep) { |
| 1146 if (parts.size() == 0) return STR(); |
| 1147 |
| 1148 STR result(parts[0]); |
| 1149 std::vector<STR>::const_iterator iter = parts.begin(); |
| 1150 ++iter; |
| 1151 |
| 1152 for (; iter != parts.end(); ++iter) { |
| 1153 result += sep; |
| 1154 result += *iter; |
| 1155 } |
| 1156 |
| 1157 return result; |
| 1158 } |
| 1159 |
| 1160 std::string JoinString(const std::vector<std::string>& parts, char sep) { |
| 1161 return JoinStringT(parts, sep); |
| 1162 } |
| 1163 |
| 1164 std::wstring JoinString(const std::vector<std::wstring>& parts, wchar_t sep) { |
| 1165 return JoinStringT(parts, sep); |
| 1166 } |
| 1167 |
1143 void SplitStringAlongWhitespace(const std::wstring& str, | 1168 void SplitStringAlongWhitespace(const std::wstring& str, |
1144 std::vector<std::wstring>* result) { | 1169 std::vector<std::wstring>* result) { |
1145 const size_t length = str.length(); | 1170 const size_t length = str.length(); |
1146 if (!length) | 1171 if (!length) |
1147 return; | 1172 return; |
1148 | 1173 |
1149 bool last_was_ws = false; | 1174 bool last_was_ws = false; |
1150 size_t last_non_ws_start = 0; | 1175 size_t last_non_ws_start = 0; |
1151 for (size_t i = 0; i < length; ++i) { | 1176 for (size_t i = 0; i < length; ++i) { |
1152 switch(str[i]) { | 1177 switch(str[i]) { |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1581 // Each input byte creates two output hex characters. | 1606 // Each input byte creates two output hex characters. |
1582 std::string ret(size * 2, '\0'); | 1607 std::string ret(size * 2, '\0'); |
1583 | 1608 |
1584 for (size_t i = 0; i < size; ++i) { | 1609 for (size_t i = 0; i < size; ++i) { |
1585 char b = reinterpret_cast<const char*>(bytes)[i]; | 1610 char b = reinterpret_cast<const char*>(bytes)[i]; |
1586 ret[(i * 2)] = kHexChars[(b >> 4) & 0xf]; | 1611 ret[(i * 2)] = kHexChars[(b >> 4) & 0xf]; |
1587 ret[(i * 2) + 1] = kHexChars[b & 0xf]; | 1612 ret[(i * 2) + 1] = kHexChars[b & 0xf]; |
1588 } | 1613 } |
1589 return ret; | 1614 return ret; |
1590 } | 1615 } |
OLD | NEW |