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

Side by Side Diff: chrome/browser/sync/util/character_set_converters_linux.cc

Issue 211019: Fix compiling of sync on linux. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 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
OLDNEW
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 11 matching lines...) Expand all
22 return true; 22 return true;
23 } 23 }
24 24
25 void TrimPathStringToValidCharacter(PathString* string) { 25 void TrimPathStringToValidCharacter(PathString* string) {
26 // Constants from http://en.wikipedia.org/wiki/UTF-8 26 // Constants from http://en.wikipedia.org/wiki/UTF-8
27 CHECK(string); 27 CHECK(string);
28 if (string->empty()) 28 if (string->empty())
29 return; 29 return;
30 if (0 == (string->at(string->length() - 1) & 0x080)) 30 if (0 == (string->at(string->length() - 1) & 0x080))
31 return; 31 return;
32 int 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 if ((c & 0x0f0) == 0xc0) // 3-byte encoded char.
47 if (2 == partial_enc_bytes) 47 if (2 == partial_enc_bytes)
48 return; 48 return;
49 else 49 else
50 break; 50 break;
51 if ((c & 0x0f8) == 0x0f0) // 4-byte encoded char. 51 if ((c & 0x0f8) == 0x0f0) // 4-byte encoded char.
52 if (3 == partial_enc_bytes) 52 if (3 == partial_enc_bytes)
53 return; 53 return;
54 else 54 else
55 break; 55 break;
56 } 56 }
57 string->resize(string->length() - 1 - partial_enc_bytes); 57 string->resize(string->length() - 1 - partial_enc_bytes);
58 } 58 }
59 59
60 } // namespace browser_sync 60 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/util/character_set_converters.h ('k') | chrome/browser/sync/util/compat_file_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698