OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2004--2005, Google Inc. | 3 * Copyright 2004--2005, Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 size_t strcatn(CTYPE* buffer, size_t buflen, | 193 size_t strcatn(CTYPE* buffer, size_t buflen, |
194 const CTYPE* source, size_t srclen = SIZE_UNKNOWN) { | 194 const CTYPE* source, size_t srclen = SIZE_UNKNOWN) { |
195 if (buflen <= 0) | 195 if (buflen <= 0) |
196 return 0; | 196 return 0; |
197 | 197 |
198 size_t bufpos = strlenn(buffer, buflen - 1); | 198 size_t bufpos = strlenn(buffer, buflen - 1); |
199 return bufpos + strcpyn(buffer + bufpos, buflen - bufpos, source, srclen); | 199 return bufpos + strcpyn(buffer + bufpos, buflen - bufpos, source, srclen); |
200 } | 200 } |
201 | 201 |
202 template<class CTYPE> | 202 template<class CTYPE> |
203 size_t sprintfn(CTYPE* buffer, size_t buflen, const CTYPE* format, ...) { | |
204 va_list args; | |
205 va_start(args, format); | |
206 size_t len = vsprintfn(buffer, buflen, format, args); | |
207 va_end(args); | |
208 return len; | |
209 } | |
210 | |
211 template<class CTYPE> | |
212 size_t vsprintfn(CTYPE* buffer, size_t buflen, const CTYPE* format, | 203 size_t vsprintfn(CTYPE* buffer, size_t buflen, const CTYPE* format, |
213 va_list args) { | 204 va_list args) { |
214 int len = vsnprintf(buffer, buflen, format, args); | 205 int len = vsnprintf(buffer, buflen, format, args); |
215 if ((len < 0) || (static_cast<size_t>(len) >= buflen)) { | 206 if ((len < 0) || (static_cast<size_t>(len) >= buflen)) { |
216 len = static_cast<int>(buflen - 1); | 207 len = static_cast<int>(buflen - 1); |
217 buffer[len] = 0; | 208 buffer[len] = 0; |
218 } | 209 } |
219 return len; | 210 return len; |
220 } | 211 } |
221 | 212 |
| 213 template<class CTYPE> |
| 214 size_t sprintfn(CTYPE* buffer, size_t buflen, const CTYPE* format, ...) { |
| 215 va_list args; |
| 216 va_start(args, format); |
| 217 size_t len = vsprintfn(buffer, buflen, format, args); |
| 218 va_end(args); |
| 219 return len; |
| 220 } |
| 221 |
222 /////////////////////////////////////////////////////////////////////////////// | 222 /////////////////////////////////////////////////////////////////////////////// |
223 // Allow safe comparing and copying ascii (not UTF-8) with both wide and | 223 // Allow safe comparing and copying ascii (not UTF-8) with both wide and |
224 // non-wide character strings. | 224 // non-wide character strings. |
225 /////////////////////////////////////////////////////////////////////////////// | 225 /////////////////////////////////////////////////////////////////////////////// |
226 | 226 |
227 inline int asccmp(const char* s1, const char* s2) { | 227 inline int asccmp(const char* s1, const char* s2) { |
228 return strcmp(s1, s2); | 228 return strcmp(s1, s2); |
229 } | 229 } |
230 inline int ascicmp(const char* s1, const char* s2) { | 230 inline int ascicmp(const char* s1, const char* s2) { |
231 return _stricmp(s1, s2); | 231 return _stricmp(s1, s2); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 struct Traits<wchar_t> { | 285 struct Traits<wchar_t> { |
286 typedef std::wstring string; | 286 typedef std::wstring string; |
287 inline static const wchar_t* Traits<wchar_t>::empty_str() { return L""; } | 287 inline static const wchar_t* Traits<wchar_t>::empty_str() { return L""; } |
288 }; | 288 }; |
289 | 289 |
290 #endif // WIN32 | 290 #endif // WIN32 |
291 | 291 |
292 } // namespace talk_base | 292 } // namespace talk_base |
293 | 293 |
294 #endif // TALK_BASE_STRINGUTILS_H__ | 294 #endif // TALK_BASE_STRINGUTILS_H__ |
OLD | NEW |