| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/strings/string_util.h" | 5 #include "base/strings/string_util.h" |
| 6 | 6 |
| 7 #include <ctype.h> | 7 #include <ctype.h> |
| 8 #include <errno.h> | 8 #include <errno.h> |
| 9 #include <math.h> | 9 #include <math.h> |
| 10 #include <stdarg.h> | 10 #include <stdarg.h> |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 int32 truncation_length = static_cast<int32>(byte_size); | 216 int32 truncation_length = static_cast<int32>(byte_size); |
| 217 int32 char_index = truncation_length - 1; | 217 int32 char_index = truncation_length - 1; |
| 218 const char* data = input.data(); | 218 const char* data = input.data(); |
| 219 | 219 |
| 220 // Using CBU8, we will move backwards from the truncation point | 220 // Using CBU8, we will move backwards from the truncation point |
| 221 // to the beginning of the string looking for a valid UTF8 | 221 // to the beginning of the string looking for a valid UTF8 |
| 222 // character. Once a full UTF8 character is found, we will | 222 // character. Once a full UTF8 character is found, we will |
| 223 // truncate the string to the end of that character. | 223 // truncate the string to the end of that character. |
| 224 while (char_index >= 0) { | 224 while (char_index >= 0) { |
| 225 int32 prev = char_index; | 225 int32 prev = char_index; |
| 226 uint32 code_point = 0; | 226 base_icu::UChar32 code_point = 0; |
| 227 CBU8_NEXT(data, char_index, truncation_length, code_point); | 227 CBU8_NEXT(data, char_index, truncation_length, code_point); |
| 228 if (!IsValidCharacter(code_point) || | 228 if (!IsValidCharacter(code_point) || |
| 229 !IsValidCodepoint(code_point)) { | 229 !IsValidCodepoint(code_point)) { |
| 230 char_index = prev - 1; | 230 char_index = prev - 1; |
| 231 } else { | 231 } else { |
| 232 break; | 232 break; |
| 233 } | 233 } |
| 234 } | 234 } |
| 235 | 235 |
| 236 if (char_index >= 0 ) | 236 if (char_index >= 0 ) |
| (...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 escape = *pattern; | 727 escape = *pattern; |
| 728 next(pattern, pattern_end); | 728 next(pattern, pattern_end); |
| 729 continue; | 729 continue; |
| 730 } | 730 } |
| 731 | 731 |
| 732 // Check if the chars match, if so, increment the ptrs. | 732 // Check if the chars match, if so, increment the ptrs. |
| 733 const CHAR* pattern_next = *pattern; | 733 const CHAR* pattern_next = *pattern; |
| 734 const CHAR* string_next = *string; | 734 const CHAR* string_next = *string; |
| 735 base_icu::UChar32 pattern_char = next(&pattern_next, pattern_end); | 735 base_icu::UChar32 pattern_char = next(&pattern_next, pattern_end); |
| 736 if (pattern_char == next(&string_next, string_end) && | 736 if (pattern_char == next(&string_next, string_end) && |
| 737 pattern_char != (base_icu::UChar32) CBU_SENTINEL) { | 737 pattern_char != CBU_SENTINEL) { |
| 738 *pattern = pattern_next; | 738 *pattern = pattern_next; |
| 739 *string = string_next; | 739 *string = string_next; |
| 740 } else { | 740 } else { |
| 741 // Uh ho, it did not match, we are done. If the last char was an | 741 // Uh oh, it did not match, we are done. If the last char was an |
| 742 // escapement, that means that it was an error to advance the ptr here, | 742 // escapement, that means that it was an error to advance the ptr here, |
| 743 // let's put it back where it was. This also mean that the MatchPattern | 743 // let's put it back where it was. This also mean that the MatchPattern |
| 744 // function will return false because if we can't match an escape char | 744 // function will return false because if we can't match an escape char |
| 745 // here, then no one will. | 745 // here, then no one will. |
| 746 if (escape) { | 746 if (escape) { |
| 747 *pattern = escape; | 747 *pattern = escape; |
| 748 } | 748 } |
| 749 return; | 749 return; |
| 750 } | 750 } |
| 751 | 751 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 883 } | 883 } |
| 884 | 884 |
| 885 } // namespace | 885 } // namespace |
| 886 | 886 |
| 887 size_t base::strlcpy(char* dst, const char* src, size_t dst_size) { | 887 size_t base::strlcpy(char* dst, const char* src, size_t dst_size) { |
| 888 return lcpyT<char>(dst, src, dst_size); | 888 return lcpyT<char>(dst, src, dst_size); |
| 889 } | 889 } |
| 890 size_t base::wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) { | 890 size_t base::wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) { |
| 891 return lcpyT<wchar_t>(dst, src, dst_size); | 891 return lcpyT<wchar_t>(dst, src, dst_size); |
| 892 } | 892 } |
| OLD | NEW |