本文整理汇总了C++中PathString类的典型用法代码示例。如果您正苦于以下问题:C++ PathString类的具体用法?C++ PathString怎么用?C++ PathString使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PathString类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: isTerminatedByRedundantSeparator
/**
* 文字列が余分なセパレータで終わっているかどうかを返します。
*/
bool isTerminatedByRedundantSeparator(const PathString &s)
{
// 完全修飾パス
// \\Server\a\ => true?
// \\Server\ => true?
// \\?\C:\ => false
// \\?\ => false
// C:\a\ => true
// C:\ => false
//
// 非完全修飾パス
// \ => false
// C:a\ => true
// .\ => true
// a\ => true
std::size_t lastSepPos = s.size();
NativeChar prevChar = AUSH_NATIVE_L('\0');
NativeChar lastSepPrevChar = AUSH_NATIVE_L('\0');
for(std::size_t pos = 0; pos < s.size(); pos = next_char_pos(s, pos)){
NativeChar currChar = s[pos];
if(is_separator()(currChar)){
lastSepPos = pos;
lastSepPrevChar = prevChar;
}
prevChar = currChar;
}
return (lastSepPos + 1 == s.size()
&& lastSepPrevChar != AUSH_NATIVE_L(':')
&& lastSepPrevChar != AUSH_NATIVE_L('?')
&& lastSepPrevChar != AUSH_NATIVE_L('\0'));
}
示例2: get_program_directory
PathString get_program_directory()
{
PathString directory;
DWORD result = GetModuleFileNameA(
GetModuleHandleA(0),
&directory[0],
static_cast<DWORD>(directory.max_size())
);
// GetModuleFilenameA failed!
assert(result != 0);
char* path = &directory[0];
char* sep;
if (result != 0)
{
sep = strrchr(path, PATH_SEPARATOR);
if (sep)
{
int32_t index = static_cast<int32_t>(sep - path);
directory[index] = '\0';
directory.recompute_size();
}
}
return directory;
}
示例3: FCIMPL0
FCIMPLEND
FCIMPL0(StringObject*, SystemNative::_GetModuleFileName)
{
FCALL_CONTRACT;
STRINGREF refRetVal = NULL;
HELPER_METHOD_FRAME_BEGIN_RET_1(refRetVal);
if (g_pCachedModuleFileName)
{
refRetVal = StringObject::NewString(g_pCachedModuleFileName);
}
else
{
PathString wszFilePathString;
DWORD lgth = WszGetModuleFileName(NULL, wszFilePathString);
if (!lgth)
{
COMPlusThrowWin32();
}
refRetVal = StringObject::NewString(wszFilePathString.GetUnicode());
}
HELPER_METHOD_FRAME_END();
return (StringObject*)OBJECTREFToObject(refRetVal);
}
示例4: m_p
ZFile::ZFile(const PathString& strPath, DWORD how) :
m_p(NULL)
{
// BT - CSS - 12/8/2011 - Fixing 128 character path limit.
DWORD dwDesiredAccess = GENERIC_READ;
DWORD dwShareMode = FILE_SHARE_WRITE;
DWORD dwCreationDisposition = OPEN_EXISTING;
if((how & OF_WRITE) == OF_WRITE)
dwDesiredAccess = GENERIC_WRITE;
if((how & OF_SHARE_DENY_WRITE) == OF_SHARE_DENY_WRITE)
dwShareMode = FILE_SHARE_READ;
if((how & OF_CREATE) == OF_CREATE)
dwCreationDisposition = CREATE_ALWAYS;
// Unicode markers / wide format enables up to 32K path length.
PathString unicodePath("\\\\?\\");
// If the path is relative, don't use unicode marker.
if(strPath.Left(1) == ZString(".") || strPath.FindAny("//") == -1)
unicodePath = strPath;
else
unicodePath += strPath;
WCHAR* pszw = new WCHAR[unicodePath.GetLength() + 1];
int result = MultiByteToWideChar(CP_ACP, 0, unicodePath, unicodePath.GetLength(), pszw, unicodePath.GetLength());
pszw[result] = NULL;
m_handle = CreateFileW(pszw, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, FILE_ATTRIBUTE_NORMAL, NULL);
delete pszw;
// BT - End fix.
}
示例5: get
virtual String get(const String& key) const
{
using namespace std;
PathString path = base_path.c_str();
path += key;
String value;
int fd = open(path.c_str(), O_RDONLY);
if (fd >= 0)
{
char buffer[MaxStringLength + 1];
(void)memset(buffer, 0, sizeof(buffer));
int len = read(fd, buffer, MaxStringLength);
(void)close(fd);
if (len > 0)
{
for (int i = 0; i < len; i++)
{
if (buffer[i] == ' ' || buffer[i] == '\n' || buffer[i] == '\r' )
{
buffer[i] = '\0';
break;
}
}
value = buffer;
}
}
return value;
}
示例6: get_user_application_directory
PathString get_user_application_directory(const char* application_data_path)
{
PathString result = get_environment_variable("LOCALAPPDATA");
result.append(PATH_SEPARATOR_STRING);
result.append(application_data_path);
result.normalize(PATH_SEPARATOR);
return result;
}
示例7: set
virtual void set(const String& key, const String& value)
{
using namespace std;
PathString path = base_path.c_str();
path += key;
int fd = open(path.c_str(), O_WRONLY | O_CREAT | O_TRUNC, FilePermissions);
if (fd >= 0)
{
(void)write(fd, value.c_str(), value.size()); // TODO FIXME Write loop
(void)fsync(fd);
(void)close(fd);
}
}
示例8: _ASSERTE
void Disassembler::StaticInitialize()
{
LIMITED_METHOD_CONTRACT;
#if USE_COREDISTOOLS_DISASSEMBLER
_ASSERTE(!IsAvailable());
PathString libPath;
HMODULE libraryHandle = LoadCoreDisToolsModule(libPath);
if (libraryHandle == nullptr)
return;
External_InitDisasm =
reinterpret_cast<decltype(External_InitDisasm)>(GetProcAddress(libraryHandle, "InitDisasm"));
if (External_InitDisasm == nullptr)
{
DISPLAYERROR(
W("GetProcAddress failed for library '%s', function 'InitDisasm': error %u\n"),
libPath.GetUnicode(),
GetLastError());
return;
}
External_DisasmInstruction =
reinterpret_cast<decltype(External_DisasmInstruction)>(GetProcAddress(libraryHandle, "DisasmInstruction"));
if (External_DisasmInstruction == nullptr)
{
DISPLAYERROR(
W("GetProcAddress failed for library '%s', function 'DisasmInstruction': error %u\n"),
libPath.GetUnicode(),
GetLastError());
return;
}
External_FinishDisasm =
reinterpret_cast<decltype(External_FinishDisasm)>(GetProcAddress(libraryHandle, "FinishDisasm"));
if (External_FinishDisasm == nullptr)
{
DISPLAYERROR(
W("GetProcAddress failed for library '%s', function 'FinishDisasm': error %u\n"),
libPath.GetUnicode(),
GetLastError());
return;
}
// Set this last to indicate successful load of the library and all exports
s_libraryHandle = libraryHandle;
_ASSERTE(IsAvailable());
#endif // USE_COREDISTOOLS_DISASSEMBLER
}
示例9: init
/**
* Initializes the file based backend storage by passing a path to
* the directory where the key named files will be stored.
* The return value should be 0 on success.
* If it is -ErrInvalidConfiguration then the the path name is too long to
* accommodate the trailing slash and max key length.
*/
int init(const PathString& path)
{
using namespace std;
int rv = -uavcan::ErrInvalidParam;
if (path.size() > 0)
{
base_path = path.c_str();
if (base_path.back() == '/')
{
base_path.pop_back();
}
rv = 0;
struct stat sb;
if (stat(base_path.c_str(), &sb) != 0 || !S_ISDIR(sb.st_mode))
{
rv = mkdir(base_path.c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
}
if (rv >= 0 )
{
base_path.push_back('/');
if ((base_path.size() + MaxStringLength) > MaxPathLength)
{
rv = -uavcan::ErrInvalidConfiguration;
}
}
}
return rv;
}
示例10: getFileExtension
/**
* ファイルの拡張子(ドットを含む)を返します。
*/
PathString getFileExtension(const PathString &s)
{
const PathString filename = getLastFileName(s);
if(filename.empty() || filename == AUSH_NATIVE_L(".") || filename == AUSH_NATIVE_L("..")){
return PathString();
}
const std::size_t pos = find_last_char(filename, is_dot());
if(pos >= filename.size()){
return PathString();
}
return filename.substr(pos);
}
示例11: locateFile
static bool locateFile(llvm::StringRef relativePath, PathString &path) {
// relativePath has no suffix
for (unsigned i = 0; i < searchPath.size(); ++i) {
PathString pathWOSuffix(searchPath[i]);
llvm::sys::path::append(pathWOSuffix, relativePath);
for (unsigned j = 0; j < moduleSuffixes.size(); ++j) {
path = pathWOSuffix;
path.append(moduleSuffixes[j].begin(), moduleSuffixes[j].end());
if (llvm::sys::fs::exists(path.str()))
return true;
}
}
return false;
}
示例12: Load
Bool FileSystem::Load( const PathString& fileName, void *& buffer, SizeT& size )
{
FILE * pFile;
if ( fopen_s( &pFile, fileName.ConstPtr(), "rb" ) )
{
return false;
}
fseek( pFile , 0 , SEEK_END );
size = ftell( pFile );
if ( size == 0 )
{
fclose( pFile );
return true;
}
rewind( pFile );
buffer = UnknownAllocator::Allocate( size );
if ( fread( buffer, 1, size, pFile ) != size )
{
UnknownAllocator::Deallocate( buffer );
size = 0;
fclose( pFile );
return false;
}
fclose(pFile);
return true;
}
示例13: Add
void ResourceManager::Add( const Char * name, Resource * res )
{
PathString path;
FileSystem::BuildPathName( name, path, FileSystem::PT_CACHE );
ResourceRequest req;
req.m_res = res;
StringUtils::StrCpy( req.m_path, 256, path.ConstPtr() );
if ( !res->IsPending() )
{
res->m_state |= Resource::PENDING;
pendingResources.PushBack( req );
}
resourceTable.Insert( res->GetId(), res );
}
示例14: LoadProgramFromBinaries
void ProgramCache::LoadProgramFromBinaries( Program& program )
{
PathString binFileName = m_cachePath;
binFileName += "/";
binFileName += program.m_name;
binFileName += ".bin";
if ( FileSystem::Exists( binFileName ) )
{
PathString searchStr = m_dataPath;
searchStr += "/";
searchStr += program.m_name;
searchStr += ".*";
Array< PathString > shaderFileNames;
FileSystem::Find( searchStr.ConstPtr(), shaderFileNames );
U64 binLastWriteTime = FileSystem::GetLastWriteTime( binFileName );
Bool binIsUpToDate = true;
Array< PathString >::ConstIterator it = shaderFileNames.Begin();
Array< PathString >::ConstIterator end = shaderFileNames.End();
for ( ; it != end; ++it )
{
const PathString& shaderFileName = *it;
if ( binLastWriteTime < FileSystem::GetLastWriteTime( shaderFileName ) )
{
binIsUpToDate = false;
break;
}
}
if ( binIsUpToDate )
{
SizeT size;
void * buffer;
if ( FileSystem::Load( binFileName, buffer, size ) )
{
program.m_handle = RenderDevice::CreateProgramBinary( buffer, size );
UnknownAllocator::Deallocate( buffer );
}
}
}
}
示例15: chopLastRedundantSeparator
/**
* パス末尾の余分なセパレータを切り落とした文字列を返します。
*
* 切り落とすのは余分なセパレータであり、切り落とすことによって意味が変わってしまう場合は切り落としません。
*/
PathString chopLastRedundantSeparator(const PathString &s)
{
if(isTerminatedByRedundantSeparator(s)){
return PathString(s, 0, s.size() - 1);
}
else{
return s;
}
}