1
0
forked from 0ad/0ad
0ad/source/lib/native_path.h
janwas dcd192cb60 refactor path interface:
- use wrapper class instead of std::wstring (reduces mixing of
strings/paths; allows safe+easy join via operator/ and convenient
case-insensitive comparison via operator==, avoids NativePathFromString,
similar to boost::filesystem)
- NativePath -> OsPath
- add hash and To/FromJSVal for Path
- add TS_ASSERT_PATH_EQUALS
- replace _wfopen_s with sys_OpenFile
- remove obsolete SortFiles/Directories

This was SVN commit r9107.
2011-03-23 13:36:20 +00:00

57 lines
1.8 KiB
C++

/* Copyright (c) 2010 Wildfire Games
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef INCLUDED_NATIVE_PATH
#define INCLUDED_NATIVE_PATH
#include "lib/path_util.h"
// rationale:
// users are responsible for ensuring the path doesn't contain any forbidden
// characters (including any code points >= 0x100 on anything but Windows)
typedef Path OsPath;
#if OS_WIN
static inline const Path::String& OsString(const OsPath& path)
{
return path.string();
}
#else
static inline std::string OsString(const OsPath& path)
{
const Path::String& wstring = path.string();
std::string string(wstring.length(), '\0');
for(size_t i = 0; i < wstring.length(); i++)
{
debug_assert(wstring[i] <= UCHAR_MAX);
string[i] = wstring[i];
}
return string;
}
#endif
#endif // #ifndef INCLUDED_NATIVE_PATH