Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/DefaultFileSystem.cpp

Issue 10459038: Clean up and fix Utils::ToUTF8String() and Utils::ToUTF16String() (Closed)
Patch Set: Created May 14, 2013, 1:54 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/DefaultWebRequestWinInet.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2013 Eyeo GmbH 3 * Copyright (C) 2006-2013 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 explicit RuntimeErrorWithErrno(const std::string& message) 44 explicit RuntimeErrorWithErrno(const std::string& message)
45 : std::runtime_error(message + " (" + strerror(errno) + ")") 45 : std::runtime_error(message + " (" + strerror(errno) + ")")
46 { 46 {
47 } 47 }
48 }; 48 };
49 49
50 #ifdef WIN32 50 #ifdef WIN32
51 // Paths need to be converted from UTF-8 to UTF-16 on Windows. 51 // Paths need to be converted from UTF-8 to UTF-16 on Windows.
52 std::wstring NormalizePath(const std::string& path) 52 std::wstring NormalizePath(const std::string& path)
53 { 53 {
54 return Utils::ToUTF16String(path, path.length()); 54 return Utils::ToUTF16String(path);
55 } 55 }
56 56
57 #define rename _wrename 57 #define rename _wrename
58 #define remove _wremove 58 #define remove _wremove
59 #else 59 #else
60 // POSIX systems: assume that file system encoding is UTF-8 and just use the 60 // POSIX systems: assume that file system encoding is UTF-8 and just use the
61 // file paths as they are. 61 // file paths as they are.
62 #define NormalizePath(path) (path) 62 #define NormalizePath(path) (path)
63 #endif 63 #endif
64 } 64 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 153
154 std::string DefaultFileSystem::Resolve(const std::string& path) const 154 std::string DefaultFileSystem::Resolve(const std::string& path) const
155 { 155 {
156 if (basePath == "") 156 if (basePath == "")
157 { 157 {
158 return path; 158 return path;
159 } 159 }
160 else 160 else
161 { 161 {
162 #ifdef _WIN32 162 #ifdef _WIN32
163 if (PathIsRelative(Utils::ToUTF16String(path, path.length()).c_str())) 163 if (PathIsRelative(NormalizePath(path).c_str()))
164 #else 164 #else
165 if (path.length() && *path.begin() != PATH_SEPARATOR) 165 if (path.length() && *path.begin() != PATH_SEPARATOR)
166 #endif 166 #endif
167 { 167 {
168 return basePath + PATH_SEPARATOR + path; 168 return basePath + PATH_SEPARATOR + path;
169 } 169 }
170 else 170 else
171 { 171 {
172 return path; 172 return path;
173 } 173 }
174 } 174 }
175 } 175 }
176 176
177 void DefaultFileSystem::SetBasePath(const std::string& path) 177 void DefaultFileSystem::SetBasePath(const std::string& path)
178 { 178 {
179 basePath = path; 179 basePath = path;
180 180
181 if ((*basePath.rbegin() == PATH_SEPARATOR)) 181 if ((*basePath.rbegin() == PATH_SEPARATOR))
182 { 182 {
183 basePath.resize(basePath.size() - 1); 183 basePath.resize(basePath.size() - 1);
184 } 184 }
185 } 185 }
186 186
OLDNEW
« no previous file with comments | « no previous file | src/DefaultWebRequestWinInet.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld