OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/browser/sync/util/character_set_converters.h" | 5 #include "chrome/browser/sync/util/character_set_converters.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 using std::string; | 9 using std::string; |
10 | 10 |
(...skipping 20 matching lines...) Expand all Loading... |
31 return; | 31 return; |
32 size_t partial_enc_bytes = 0; | 32 size_t partial_enc_bytes = 0; |
33 for (partial_enc_bytes = 0 ; true ; ++partial_enc_bytes) { | 33 for (partial_enc_bytes = 0 ; true ; ++partial_enc_bytes) { |
34 if (4 == partial_enc_bytes || partial_enc_bytes == string->length()) { | 34 if (4 == partial_enc_bytes || partial_enc_bytes == string->length()) { |
35 // original string was broken, garbage in, garbage out. | 35 // original string was broken, garbage in, garbage out. |
36 return; | 36 return; |
37 } | 37 } |
38 PathChar c = string->at(string->length() - 1 - partial_enc_bytes); | 38 PathChar c = string->at(string->length() - 1 - partial_enc_bytes); |
39 if ((c & 0x0c0) == 0x080) // utf continuation char; | 39 if ((c & 0x0c0) == 0x080) // utf continuation char; |
40 continue; | 40 continue; |
41 if ((c & 0x0e0) == 0x0e0) // 2-byte encoded char. | 41 if ((c & 0x0e0) == 0x0e0) { // 2-byte encoded char. |
42 if (1 == partial_enc_bytes) | 42 if (1 == partial_enc_bytes) |
43 return; | 43 return; |
44 else | 44 else |
45 break; | 45 break; |
46 if ((c & 0x0f0) == 0xc0) // 3-byte encoded char. | 46 } |
| 47 if ((c & 0x0f0) == 0xc0) { // 3-byte encoded char. |
47 if (2 == partial_enc_bytes) | 48 if (2 == partial_enc_bytes) |
48 return; | 49 return; |
49 else | 50 else |
50 break; | 51 break; |
51 if ((c & 0x0f8) == 0x0f0) // 4-byte encoded char. | 52 } |
| 53 if ((c & 0x0f8) == 0x0f0) { // 4-byte encoded char. |
52 if (3 == partial_enc_bytes) | 54 if (3 == partial_enc_bytes) |
53 return; | 55 return; |
54 else | 56 else |
55 break; | 57 break; |
| 58 } |
56 } | 59 } |
57 string->resize(string->length() - 1 - partial_enc_bytes); | 60 string->resize(string->length() - 1 - partial_enc_bytes); |
58 } | 61 } |
59 | 62 |
60 } // namespace browser_sync | 63 } // namespace browser_sync |
61 | |
OLD | NEW |