Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: base/string_util.h

Issue 6003: Portable swscanf.... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 12 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | base/string_util_posix.h » ('j') | base/string_util_win.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // This file defines utility functions for working with strings. 5 // This file defines utility functions for working with strings.
6 6
7 #ifndef BASE_STRING_UTIL_H_ 7 #ifndef BASE_STRING_UTIL_H_
8 #define BASE_STRING_UTIL_H_ 8 #define BASE_STRING_UTIL_H_
9 9
10 #include <string> 10 #include <string>
(...skipping 15 matching lines...) Expand all
26 // Compare the two strings s1 and s2 without regard to case using 26 // Compare the two strings s1 and s2 without regard to case using
27 // the current locale; returns 0 if they are equal, 1 if s1 > s2, and -1 if 27 // the current locale; returns 0 if they are equal, 1 if s1 > s2, and -1 if
28 // s2 > s1 according to a lexicographic comparison. 28 // s2 > s1 according to a lexicographic comparison.
29 int strcasecmp(const char* s1, const char* s2); 29 int strcasecmp(const char* s1, const char* s2);
30 30
31 // Compare up to count characters of s1 and s2 without regard to case using 31 // Compare up to count characters of s1 and s2 without regard to case using
32 // the current locale; returns 0 if they are equal, 1 if s1 > s2, and -1 if 32 // the current locale; returns 0 if they are equal, 1 if s1 > s2, and -1 if
33 // s2 > s1 according to a lexicographic comparison. 33 // s2 > s1 according to a lexicographic comparison.
34 int strncasecmp(const char* s1, const char* s2, size_t count); 34 int strncasecmp(const char* s1, const char* s2, size_t count);
35 35
36 // Wrapper for swscanf.
37 int vswscanf(const wchar_t* ws, const wchar_t* format, va_list arguments);
38
36 // Wrapper for vsnprintf that always null-terminates and always returns the 39 // Wrapper for vsnprintf that always null-terminates and always returns the
37 // number of characters that would be in an untruncated formatted 40 // number of characters that would be in an untruncated formatted
38 // string, even when truncation occurs. 41 // string, even when truncation occurs.
39 int vsnprintf(char* buffer, size_t size, const char* format, va_list arguments); 42 int vsnprintf(char* buffer, size_t size, const char* format, va_list arguments);
40 43
41 // vswprintf always null-terminates, but when truncation occurs, it will either 44 // vswprintf always null-terminates, but when truncation occurs, it will either
42 // return -1 or the number of characters that would be in an untruncated 45 // return -1 or the number of characters that would be in an untruncated
43 // formatted string. The actual return value depends on the underlying 46 // formatted string. The actual return value depends on the underlying
44 // C library's vswprintf implementation. 47 // C library's vswprintf implementation.
45 int vswprintf(wchar_t* buffer, size_t size, 48 int vswprintf(wchar_t* buffer, size_t size,
46 const wchar_t* format, va_list arguments); 49 const wchar_t* format, va_list arguments);
47 50
48 // Some of these implementations need to be inlined. 51 // Some of these implementations need to be inlined.
49 52
53 inline int swscanf(const wchar_t* ws, const wchar_t* format, ...) {
54 va_list arguments;
55 va_start(arguments, format);
56 int result = vswscanf(ws, format, arguments);
57 va_end(arguments);
58 return result;
59 }
60
50 inline int snprintf(char* buffer, size_t size, const char* format, ...) { 61 inline int snprintf(char* buffer, size_t size, const char* format, ...) {
51 va_list arguments; 62 va_list arguments;
52 va_start(arguments, format); 63 va_start(arguments, format);
53 int result = vsnprintf(buffer, size, format, arguments); 64 int result = vsnprintf(buffer, size, format, arguments);
54 va_end(arguments); 65 va_end(arguments);
55 return result; 66 return result;
56 } 67 }
57 68
58 inline int swprintf(wchar_t* buffer, size_t size, const wchar_t* format, ...) { 69 inline int swprintf(wchar_t* buffer, size_t size, const wchar_t* format, ...) {
59 va_list arguments; 70 va_list arguments;
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 // Returns true if the string passed in matches the pattern. The pattern 522 // Returns true if the string passed in matches the pattern. The pattern
512 // string can contain wildcards like * and ? 523 // string can contain wildcards like * and ?
513 // TODO(iyengar) This function may not work correctly for CJK strings as 524 // TODO(iyengar) This function may not work correctly for CJK strings as
514 // it does individual character matches. 525 // it does individual character matches.
515 // The backslash character (\) is an escape character for * and ? 526 // The backslash character (\) is an escape character for * and ?
516 bool MatchPattern(const std::wstring& string, const std::wstring& pattern); 527 bool MatchPattern(const std::wstring& string, const std::wstring& pattern);
517 bool MatchPattern(const std::string& string, const std::string& pattern); 528 bool MatchPattern(const std::string& string, const std::string& pattern);
518 529
519 #endif // BASE_STRING_UTIL_H_ 530 #endif // BASE_STRING_UTIL_H_
520 531
OLDNEW
« no previous file with comments | « no previous file | base/string_util_posix.h » ('j') | base/string_util_win.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698