CatapultServer  v0.5.0.1 (Elephant)
PathUtils.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "RawBuffer.h"
23 
24 namespace catapult { namespace utils {
25 
27  constexpr bool IsDirectorySeparator(char ch) {
28 #ifdef _WIN32
29  return '\\' == ch || '/' == ch;
30 #else
31  return '/' == ch;
32 #endif
33  }
34 
36  constexpr const char* AdvanceToEnd(const char* str) {
37  const auto* pEnd = str;
38  while (*pEnd != '\0') ++pEnd;
39  return pEnd;
40  }
41 
44  constexpr const char* ExtractFilename(const char* fullPath) {
45  const auto* pEnd = AdvanceToEnd(fullPath);
46  for (const auto* pCh = pEnd - 1; pCh >= fullPath; --pCh) {
47  if (IsDirectorySeparator(*pCh))
48  return pCh + 1;
49  }
50 
51  return fullPath;
52  }
53 
56  constexpr const char* ExtractDirectoryAndFilename(const char* fullPath) {
57  const auto* pEnd = ExtractFilename(fullPath);
58 
59  // skip consecutive directory separators
60  const auto* pCh = pEnd - 1;
61  for (; pCh >= fullPath; --pCh) {
62  if (!IsDirectorySeparator(*pCh))
63  break;
64  }
65 
66  // find next directory separator
67  for (; pCh >= fullPath; --pCh) {
68  if (IsDirectorySeparator(*pCh))
69  return pCh + 1;
70  }
71 
72  return fullPath;
73  }
74 
77  constexpr RawString ExtractDirectoryName(const char* fullPath) {
78  const auto* pDirectoryName = ExtractDirectoryAndFilename(fullPath);
79  const auto* pEnd = ExtractFilename(fullPath);
80 
81  const auto* pCh = pDirectoryName;
82  for (; pCh < pEnd; ++pCh) {
83  if (IsDirectorySeparator(*pCh))
84  break;
85  }
86 
87  return { pDirectoryName, static_cast<size_t>(pCh - pDirectoryName) };
88  }
89 }}
Parser.NamespacesParser.clearNameStackAndFindSemiColon
def clearNameStackAndFindSemiColon(self)
Definition: Parser.py:380
Parser.NamespacesParser._parseNormalEquals
def _parseNormalEquals(self, tok)
Definition: Parser.py:261
Parser.NamespacesParser.collectClass
def collectClass(self, tok)
Definition: Parser.py:493
catapult::utils::ExtractDirectoryName
constexpr RawString ExtractDirectoryName(const char *fullPath)
Definition: PathUtils.h:77
Parser.NamespacesParser.lineNumber
lineNumber
Definition: Parser.py:134
Parser.NamespacesParser.templateBracketLevel
templateBracketLevel
Definition: Parser.py:138
Parser.TemplateError
Definition: Parser.py:63
Parser.NamespacesParser.collectEnum
def collectEnum(self, tok)
Definition: Parser.py:514
catapult::utils::IsDirectorySeparator
constexpr bool IsDirectorySeparator(char ch)
Gets a value indicating whether or not ch is a directory separator.
Definition: PathUtils.h:27
Parser.debug
def debug(*args)
Definition: Parser.py:46
Parser.NamespacesParser.clearNameStack
def clearNameStack(self)
Definition: Parser.py:376
Parser.NamespacesParser.namespaces
namespaces
Definition: Parser.py:148
Parser.NamespacesParser.currentParenLevel
currentParenLevel
Definition: Parser.py:146
Parser.NamespaceInfo.__setattr__
def __setattr__(self, key, value)
Definition: Parser.py:79
Parser.NamespacesParser.switchToNormal
def switchToNormal(self)
Definition: Parser.py:446
Parser.NamespaceInfo.__repr__
def __repr__(self)
Definition: Parser.py:116
Parser.NamespacesParser._quitIfNoNamestack
def _quitIfNoNamestack(self, token)
Definition: Parser.py:156
Parser.NamespacesParser.parseNormal
def parseNormal(self, tok)
Definition: Parser.py:160
Parser.NamespacesParser.collectTemplate
def collectTemplate(self, tok)
Definition: Parser.py:463
Parser.NamespacesParser._operatorMinus
def _operatorMinus(self, nextToken)
Definition: Parser.py:292
Parser.NamespacesParser.templateContent
templateContent
Definition: Parser.py:140
Parser.NamespaceInfo.hadTest
hadTest
Definition: Parser.py:92
colorPrint.warning
def warning(*args)
Definition: colorPrint.py:10
Parser.has
def has(tokenName, stack)
Definition: Parser.py:56
RawBuffer.h
Parser.NamespacesParser.addNamespace
def addNamespace(self)
Definition: Parser.py:351
Parser.NamespaceInfo.__eq__
def __eq__(self, other)
Definition: Parser.py:110
Parser.NamespacesParser.insideTemplateCallback
insideTemplateCallback
Definition: Parser.py:150
Parser.NamespacesParser.collectNs
def collectNs(self, tok)
Definition: Parser.py:450
Parser.NamespacesParser.findSemiColon
def findSemiColon(self, tok)
Definition: Parser.py:598
Parser.info
def info(*args)
Definition: Parser.py:41
Parser.NamespaceInfo.hadForward
hadForward
Definition: Parser.py:87
Parser.NamespacesParser.currentBraceLevel
currentBraceLevel
Definition: Parser.py:143
Parser.NamespaceInfo.hadFuncOrVar
hadFuncOrVar
Definition: Parser.py:88
Parser.NamespacesParser
Definition: Parser.py:130
Parser.NamespacesParser.currentColonBraceLevel
currentColonBraceLevel
Definition: Parser.py:144
Parser.TemplateError.__init__
def __init__(self, name, line)
Definition: Parser.py:64
Parser.NamespacesParser.nameStack
nameStack
Definition: Parser.py:145
Parser.NamespacesParser.saveTokenOrBye
def saveTokenOrBye(self, previousToken, token, tokenName)
Definition: Parser.py:266
Parser.NamespacesParser.mode
mode
Definition: Parser.py:135
colorPrint
Definition: colorPrint.py:1
catapult::utils::ExtractDirectoryAndFilename
constexpr const char * ExtractDirectoryAndFilename(const char *fullPath)
Definition: PathUtils.h:56
Parser.NamespacesParser.findClassEnd
def findClassEnd(self, tok)
Definition: Parser.py:536
Parser.NamespaceInfo.name
name
Definition: Parser.py:74
Parser.NamespaceInfo.hadEnum
hadEnum
Definition: Parser.py:90
Parser.NamespacesParser.addTemplateError
def addTemplateError(self, line)
Definition: Parser.py:371
Parser.NamespaceInfo.hadUsing
hadUsing
Definition: Parser.py:91
Parser.NamespacesParser._operatorPlus
def _operatorPlus(self, nextToken)
Definition: Parser.py:282
Parser.NamespaceInfo.__init__
def __init__(self, current)
Definition: Parser.py:71
Parser.NamespaceInfo.hadDefineMacro
hadDefineMacro
Definition: Parser.py:96
Parser.NamespacesParser.findCloseParen
def findCloseParen(self, tok)
Definition: Parser.py:613
Parser.TemplateError.line
line
Definition: Parser.py:66
Parser.NamespaceInfo
Definition: Parser.py:70
Parser.Mode
Definition: Parser.py:14
Parser.NextTokenBehavior
Definition: Parser.py:27
catapult::utils::ExtractFilename
constexpr const char * ExtractFilename(const char *fullPath)
Definition: PathUtils.h:44
Parser.NamespacesParser.path
path
Definition: Parser.py:133
Parser.NamespacesParser.parseFile
def parseFile(self, inputStream)
Definition: Parser.py:392
Parser.TemplateError.name
name
Definition: Parser.py:65
Parser.NamespaceInfo.__hash__
def __hash__(self)
Definition: Parser.py:113
Parser.trace_print
def trace_print(*args)
Definition: Parser.py:51
Parser.NamespacesParser.closingBraceCallback
closingBraceCallback
Definition: Parser.py:147
Parser.NamespacesParser.quit
def quit(self, tok)
Definition: Parser.py:416
Parser.NamespaceInfo.__getattr__
def __getattr__(self, key)
Definition: Parser.py:76
Parser.NamespaceInfo.__ior__
def __ior__(self, other)
Definition: Parser.py:86
Parser.NamespacesParser.templateErrors
templateErrors
Definition: Parser.py:149
Parser.NamespaceInfo.empty
def empty(self)
Definition: Parser.py:99
Parser.NamespacesParser.checkProperties
def checkProperties(self)
Definition: Parser.py:578
catapult::utils::RawString
A const string buffer.
Definition: RawBuffer.h:68
Parser.NamespacesParser.wasTemplateInstantiation
wasTemplateInstantiation
Definition: Parser.py:141
Parser.NamespacesParser.collectOperator
def collectOperator(self)
Definition: Parser.py:312
Parser.NamespacesParser.templateHadClass
templateHadClass
Definition: Parser.py:139
Parser.NamespacesParser._parseNormalOpenBracket
def _parseNormalOpenBracket(self, tok)
Definition: Parser.py:218
Parser.NamespaceInfo.hadInclude
hadInclude
Definition: Parser.py:94
Parser.NamespacesParser._parseNormalStringLiteral
def _parseNormalStringLiteral(self, tok)
Definition: Parser.py:213
Parser.NamespacesParser._parseNormalSemiColon
def _parseNormalSemiColon(self, tok)
Definition: Parser.py:251
Parser.NamespaceInfo.properties
properties
Definition: Parser.py:72
Parser.NamespaceInfo.hadClass
hadClass
Definition: Parser.py:89
Parser.NamespacesParser.tok
tok
Definition: Parser.py:152
Parser.NamespacesParser.findCloseBrace
def findCloseBrace(self, tok)
Definition: Parser.py:548
Parser.NamespaceInfo.hadConstant
hadConstant
Definition: Parser.py:93
catapult
Definition: AddressExtractionExtension.cpp:28
Parser.NamespacesParser._parseNormalPrecompMacro
def _parseNormalPrecompMacro(self, tok)
Definition: Parser.py:224
Parser.NamespacesParser._operatorLessThan
def _operatorLessThan(self, nextToken)
Definition: Parser.py:302
Parser.NamespacesParser.hadParens
hadParens
Definition: Parser.py:142
Parser.NamespacesParser._parseNormalBrace
def _parseNormalBrace(self, tok)
Definition: Parser.py:240
Parser.NamespacesParser._checkFuncOrVar
def _checkFuncOrVar(self)
Definition: Parser.py:563
Parser.NamespacesParser._parseNormalOpenParen
def _parseNormalOpenParen(self, tok)
Definition: Parser.py:233
Parser.NamespacesParser.errorReporter
errorReporter
Definition: Parser.py:132
Parser.NamespacesParser.namespaceStack
namespaceStack
Definition: Parser.py:137
Parser.NamespaceInfo.current
current
Definition: Parser.py:73
Parser.NamespacesParser._operatorEquals
def _operatorEquals(self, nextToken)
Definition: Parser.py:273
Parser.NamespacesParser.__init__
def __init__(self, errorReporter, path)
Definition: Parser.py:131
catapult::utils::AdvanceToEnd
constexpr const char * AdvanceToEnd(const char *str)
Advances str to its end (the NUL terminator).
Definition: PathUtils.h:36
Parser.NamespacesParser._parseNormalName
def _parseNormalName(self, tok)
Definition: Parser.py:185
Parser.NamespacesParser.curNsPart
curNsPart
Definition: Parser.py:136