Revised String class

Renamed String::Substr to SubString


Former-commit-id: 6aa925799e71af6916f7808368a3faa26efbe1bc
This commit is contained in:
Lynix 2013-06-19 02:25:19 +02:00
parent c1e57c829c
commit b0c46b2384
10 changed files with 189 additions and 1099 deletions

View File

@ -29,7 +29,7 @@ class NAZARA_API NzByteArray : public NzHashable
NzByteArray& Append(nzUInt8 byte); NzByteArray& Append(nzUInt8 byte);
NzByteArray& Append(const nzUInt8* buffer, unsigned int length); NzByteArray& Append(const nzUInt8* buffer, unsigned int length);
NzByteArray& Append(const NzByteArray& byteArray); NzByteArray& Append(const NzByteArray& array);
void Clear(bool keepBuffer = false); void Clear(bool keepBuffer = false);
@ -78,13 +78,13 @@ class NAZARA_API NzByteArray : public NzHashable
nzUInt8& operator[](unsigned int pos); nzUInt8& operator[](unsigned int pos);
nzUInt8 operator[](unsigned int pos) const; nzUInt8 operator[](unsigned int pos) const;
NzByteArray& operator=(const NzByteArray& byteArray); NzByteArray& operator=(const NzByteArray& array);
NzByteArray& operator=(NzByteArray&& byteArray) noexcept; NzByteArray& operator=(NzByteArray&& array) noexcept;
NzByteArray operator+(nzUInt8 byte) const; NzByteArray operator+(nzUInt8 byte) const;
NzByteArray operator+(const NzByteArray& byteArray) const; NzByteArray operator+(const NzByteArray& array) const;
NzByteArray& operator+=(nzUInt8 byte); NzByteArray& operator+=(nzUInt8 byte);
NzByteArray& operator+=(const NzByteArray& byteArray); NzByteArray& operator+=(const NzByteArray& array);
static int Compare(const NzByteArray& first, const NzByteArray& second); static int Compare(const NzByteArray& first, const NzByteArray& second);

View File

@ -35,7 +35,7 @@ bool NzResourceLoader<Type, Parameters>::LoadFromFile(Type* resource, const NzSt
#endif #endif
NzString path = NzFile::NormalizePath(filePath); NzString path = NzFile::NormalizePath(filePath);
NzString ext = path.SubstrFrom('.', -1, true); NzString ext = path.SubStringFrom('.', -1, true);
if (ext.IsEmpty()) if (ext.IsEmpty())
{ {
NazaraError("Failed to get file extension from \"" + filePath + '"'); NazaraError("Failed to get file extension from \"" + filePath + '"');

View File

@ -34,6 +34,7 @@ class NAZARA_API NzString : public NzHashable
NzString(); NzString();
explicit NzString(char character); explicit NzString(char character);
NzString(const char* string); NzString(const char* string);
NzString(const char* string, unsigned int length);
NzString(const std::string& string); NzString(const std::string& string);
NzString(const NzString& string); NzString(const NzString& string);
NzString(NzString&& string) noexcept; NzString(NzString&& string) noexcept;
@ -59,6 +60,7 @@ class NAZARA_API NzString : public NzHashable
bool EndsWith(char character, nzUInt32 flags = None) const; bool EndsWith(char character, nzUInt32 flags = None) const;
bool EndsWith(const char* string, nzUInt32 flags = None) const; bool EndsWith(const char* string, nzUInt32 flags = None) const;
bool EndsWith(const char* string, unsigned int length, nzUInt32 flags = None) const;
bool EndsWith(const NzString& string, nzUInt32 flags = None) const; bool EndsWith(const NzString& string, nzUInt32 flags = None) const;
unsigned int Find(char character, int start = 0, nzUInt32 flags = None) const; unsigned int Find(char character, int start = 0, nzUInt32 flags = None) const;
@ -90,6 +92,7 @@ class NAZARA_API NzString : public NzHashable
NzString& Insert(int pos, char character); NzString& Insert(int pos, char character);
NzString& Insert(int pos, const char* string); NzString& Insert(int pos, const char* string);
NzString& Insert(int pos, const char* string, unsigned int length);
NzString& Insert(int pos, const NzString& string); NzString& Insert(int pos, const NzString& string);
bool IsEmpty() const; bool IsEmpty() const;
@ -101,10 +104,12 @@ class NAZARA_API NzString : public NzHashable
NzString& Prepend(char character); NzString& Prepend(char character);
NzString& Prepend(const char* string); NzString& Prepend(const char* string);
NzString& Prepend(const char* string, unsigned int length);
NzString& Prepend(const NzString& string); NzString& Prepend(const NzString& string);
unsigned int Replace(char oldCharacter, char newCharacter, int start = 0, nzUInt32 flags = None); unsigned int Replace(char oldCharacter, char newCharacter, int start = 0, nzUInt32 flags = None);
unsigned int Replace(const char* oldString, const char* replaceString, int start = 0, nzUInt32 flags = None); unsigned int Replace(const char* oldString, const char* replaceString, int start = 0, nzUInt32 flags = None);
unsigned int Replace(const char* oldString, unsigned int oldLength, const char* replaceString, unsigned int replaceLength, int start = 0, nzUInt32 flags = None);
unsigned int Replace(const NzString& oldString, const NzString& replaceString, int start = 0, nzUInt32 flags = None); unsigned int Replace(const NzString& oldString, const NzString& replaceString, int start = 0, nzUInt32 flags = None);
unsigned int ReplaceAny(const char* oldCharacters, char replaceCharacter, int start = 0, nzUInt32 flags = None); unsigned int ReplaceAny(const char* oldCharacters, char replaceCharacter, int start = 0, nzUInt32 flags = None);
//unsigned int ReplaceAny(const char* oldCharacters, const char* replaceString, int start = 0, nzUInt32 flags = None); //unsigned int ReplaceAny(const char* oldCharacters, const char* replaceString, int start = 0, nzUInt32 flags = None);
@ -123,6 +128,7 @@ class NAZARA_API NzString : public NzHashable
unsigned int Split(std::vector<NzString>& result, char separation = ' ', int start = 0, nzUInt32 flags = None) const; unsigned int Split(std::vector<NzString>& result, char separation = ' ', int start = 0, nzUInt32 flags = None) const;
unsigned int Split(std::vector<NzString>& result, const char* separation, int start = 0, nzUInt32 flags = None) const; unsigned int Split(std::vector<NzString>& result, const char* separation, int start = 0, nzUInt32 flags = None) const;
unsigned int Split(std::vector<NzString>& result, const char* separation, unsigned int length, int start = 0, nzUInt32 flags = None) const;
unsigned int Split(std::vector<NzString>& result, const NzString& separation, int start = 0, nzUInt32 flags = None) const; unsigned int Split(std::vector<NzString>& result, const NzString& separation, int start = 0, nzUInt32 flags = None) const;
unsigned int SplitAny(std::vector<NzString>& result, const char* separations, int start = 0, nzUInt32 flags = None) const; unsigned int SplitAny(std::vector<NzString>& result, const char* separations, int start = 0, nzUInt32 flags = None) const;
unsigned int SplitAny(std::vector<NzString>& result, const NzString& separations, int start = 0, nzUInt32 flags = None) const; unsigned int SplitAny(std::vector<NzString>& result, const NzString& separations, int start = 0, nzUInt32 flags = None) const;
@ -131,13 +137,15 @@ class NAZARA_API NzString : public NzHashable
bool StartsWith(const char* string, nzUInt32 flags = None) const; bool StartsWith(const char* string, nzUInt32 flags = None) const;
bool StartsWith(const NzString& string, nzUInt32 flags = None) const; bool StartsWith(const NzString& string, nzUInt32 flags = None) const;
NzString Substr(int startPos, int endPos = -1) const; NzString SubString(int startPos, int endPos = -1) const;
NzString SubstrFrom(char character, int startPos = 0, bool fromLast = false, bool include = false, nzUInt32 flags = None) const; NzString SubStringFrom(char character, int startPos = 0, bool fromLast = false, bool include = false, nzUInt32 flags = None) const;
NzString SubstrFrom(const char *string, int startPos = 0, bool fromLast = false, bool include = false, nzUInt32 flags = None) const; NzString SubStringFrom(const char *string, int startPos = 0, bool fromLast = false, bool include = false, nzUInt32 flags = None) const;
NzString SubstrFrom(const NzString& string, int startPos = 0, bool fromLast = false, bool include = false, nzUInt32 flags = None) const; NzString SubStringFrom(const char *string, unsigned int length, int startPos = 0, bool fromLast = false, bool include = false, nzUInt32 flags = None) const;
NzString SubstrTo(char character, int startPos = 0, bool toLast = false, bool include = false, nzUInt32 flags = None) const; NzString SubStringFrom(const NzString& string, int startPos = 0, bool fromLast = false, bool include = false, nzUInt32 flags = None) const;
NzString SubstrTo(const char *string, int startPos = 0, bool toLast = false, bool include = false, nzUInt32 flags = None) const; NzString SubStringTo(char character, int startPos = 0, bool toLast = false, bool include = false, nzUInt32 flags = None) const;
NzString SubstrTo(const NzString& string, int startPos = 0, bool toLast = false, bool include = false, nzUInt32 flags = None) const; NzString SubStringTo(const char *string, int startPos = 0, bool toLast = false, bool include = false, nzUInt32 flags = None) const;
NzString SubStringTo(const char *string, unsigned int length, int startPos = 0, bool toLast = false, bool include = false, nzUInt32 flags = None) const;
NzString SubStringTo(const NzString& string, int startPos = 0, bool toLast = false, bool include = false, nzUInt32 flags = None) const;
void Swap(NzString& str); void Swap(NzString& str);

View File

@ -262,9 +262,9 @@ bool NzDirectory::Create(const NzString& dirPath, bool recursive)
do do
{ {
NzString p = path.Substr(0, foundPos); NzString p = path.SubString(0, foundPos);
if (p.EndsWith(NAZARA_DIRECTORY_SEPARATOR)) if (p.EndsWith(NAZARA_DIRECTORY_SEPARATOR))
p = p.Substr(0, -2); p = p.SubString(0, -2);
if (!NzDirectoryImpl::Exists(p) && !NzDirectoryImpl::Create(p)) if (!NzDirectoryImpl::Exists(p) && !NzDirectoryImpl::Create(p))
return false; return false;

View File

@ -162,14 +162,14 @@ NzString NzFile::GetDirectory() const
{ {
NazaraLock(m_mutex) NazaraLock(m_mutex)
return m_filePath.SubstrTo(NAZARA_DIRECTORY_SEPARATOR, -1, true, true); return m_filePath.SubStringTo(NAZARA_DIRECTORY_SEPARATOR, -1, true, true);
} }
NzString NzFile::GetFileName() const NzString NzFile::GetFileName() const
{ {
NazaraLock(m_mutex) NazaraLock(m_mutex)
return m_filePath.SubstrFrom(NAZARA_DIRECTORY_SEPARATOR, -1, true); return m_filePath.SubStringFrom(NAZARA_DIRECTORY_SEPARATOR, -1, true);
} }
time_t NzFile::GetLastAccessTime() const time_t NzFile::GetLastAccessTime() const
@ -501,8 +501,8 @@ NzString NzFile::AbsolutePath(const NzString& filePath)
} }
else if (path.StartsWith('\\')) // Spécial : '\' fait référence au disque racine else if (path.StartsWith('\\')) // Spécial : '\' fait référence au disque racine
{ {
NzString drive = NzDirectory::GetCurrent().SubstrTo('\\'); NzString drive = NzDirectory::GetCurrent().SubStringTo('\\');
NzString end = path.Substr(1, -1); NzString end = path.SubString(1, -1);
if (end.IsEmpty()) if (end.IsEmpty())
path = drive; path = drive;
else else
@ -604,7 +604,7 @@ time_t NzFile::GetCreationTime(const NzString& filePath)
NzString NzFile::GetDirectory(const NzString& filePath) NzString NzFile::GetDirectory(const NzString& filePath)
{ {
return filePath.SubstrTo(NAZARA_DIRECTORY_SEPARATOR, -1, true, true); return filePath.SubStringTo(NAZARA_DIRECTORY_SEPARATOR, -1, true, true);
} }
time_t NzFile::GetLastAccessTime(const NzString& filePath) time_t NzFile::GetLastAccessTime(const NzString& filePath)

File diff suppressed because it is too large Load Diff

View File

@ -151,7 +151,7 @@ bool NzMTLParser::Parse()
} }
else if (keyword == "map_ka") else if (keyword == "map_ka")
{ {
NzString map = m_currentLine.Substr(m_currentLine.GetWordPosition(1)); NzString map = m_currentLine.SubString(m_currentLine.GetWordPosition(1));
if (!map.IsEmpty()) if (!map.IsEmpty())
{ {
if (!currentMaterial) if (!currentMaterial)
@ -166,7 +166,7 @@ bool NzMTLParser::Parse()
} }
else if (keyword == "map_kd") else if (keyword == "map_kd")
{ {
NzString map = m_currentLine.Substr(m_currentLine.GetWordPosition(1)); NzString map = m_currentLine.SubString(m_currentLine.GetWordPosition(1));
if (!map.IsEmpty()) if (!map.IsEmpty())
{ {
if (!currentMaterial) if (!currentMaterial)
@ -181,7 +181,7 @@ bool NzMTLParser::Parse()
} }
else if (keyword == "map_ks") else if (keyword == "map_ks")
{ {
NzString map = m_currentLine.Substr(m_currentLine.GetWordPosition(1)); NzString map = m_currentLine.SubString(m_currentLine.GetWordPosition(1));
if (!map.IsEmpty()) if (!map.IsEmpty())
{ {
if (!currentMaterial) if (!currentMaterial)
@ -196,7 +196,7 @@ bool NzMTLParser::Parse()
} }
else if (keyword == "map_bump" || keyword == "bump") else if (keyword == "map_bump" || keyword == "bump")
{ {
NzString map = m_currentLine.Substr(m_currentLine.GetWordPosition(1)); NzString map = m_currentLine.SubString(m_currentLine.GetWordPosition(1));
if (!map.IsEmpty()) if (!map.IsEmpty())
{ {
if (!currentMaterial) if (!currentMaterial)
@ -211,7 +211,7 @@ bool NzMTLParser::Parse()
} }
else if (keyword == "map_d") else if (keyword == "map_d")
{ {
NzString map = m_currentLine.Substr(m_currentLine.GetWordPosition(1)); NzString map = m_currentLine.SubString(m_currentLine.GetWordPosition(1));
if (!map.IsEmpty()) if (!map.IsEmpty())
{ {
if (!currentMaterial) if (!currentMaterial)
@ -226,7 +226,7 @@ bool NzMTLParser::Parse()
} }
else if (keyword == "map_decal" || keyword == "decal") else if (keyword == "map_decal" || keyword == "decal")
{ {
NzString map = m_currentLine.Substr(m_currentLine.GetWordPosition(1)); NzString map = m_currentLine.SubString(m_currentLine.GetWordPosition(1));
if (!map.IsEmpty()) if (!map.IsEmpty())
{ {
if (!currentMaterial) if (!currentMaterial)
@ -241,7 +241,7 @@ bool NzMTLParser::Parse()
} }
else if (keyword == "map_disp" || keyword == "disp") else if (keyword == "map_disp" || keyword == "disp")
{ {
NzString map = m_currentLine.Substr(m_currentLine.GetWordPosition(1)); NzString map = m_currentLine.SubString(m_currentLine.GetWordPosition(1));
if (!map.IsEmpty()) if (!map.IsEmpty())
{ {
if (!currentMaterial) if (!currentMaterial)
@ -256,7 +256,7 @@ bool NzMTLParser::Parse()
} }
else if (keyword == "map_refl" || keyword == "refl") else if (keyword == "map_refl" || keyword == "refl")
{ {
NzString map = m_currentLine.Substr(m_currentLine.GetWordPosition(1)); NzString map = m_currentLine.SubString(m_currentLine.GetWordPosition(1));
if (!map.IsEmpty()) if (!map.IsEmpty())
{ {
if (!currentMaterial) if (!currentMaterial)
@ -271,7 +271,7 @@ bool NzMTLParser::Parse()
} }
else if (keyword == "newmtl") else if (keyword == "newmtl")
{ {
NzString materialName = m_currentLine.Substr(m_currentLine.GetWordPosition(1)); NzString materialName = m_currentLine.SubString(m_currentLine.GetWordPosition(1));
if (!materialName.IsEmpty()) if (!materialName.IsEmpty())
currentMaterial = &m_materials[materialName]; currentMaterial = &m_materials[materialName];
#if NAZARA_UTILITY_STRICT_RESOURCE_PARSING #if NAZARA_UTILITY_STRICT_RESOURCE_PARSING
@ -305,7 +305,7 @@ bool NzMTLParser::Advance(bool required)
m_lineCount++; m_lineCount++;
m_currentLine = m_stream.ReadLine(); m_currentLine = m_stream.ReadLine();
m_currentLine = m_currentLine.SubstrTo("#"); // On ignore les commentaires m_currentLine = m_currentLine.SubStringTo("#"); // On ignore les commentaires
m_currentLine.Simplify(); // Pour un traitement plus simple m_currentLine.Simplify(); // Pour un traitement plus simple
} }
while (m_currentLine.IsEmpty()); while (m_currentLine.IsEmpty());

View File

@ -237,7 +237,7 @@ bool NzOBJParser::Parse()
UnrecognizedLine(); UnrecognizedLine();
#endif #endif
m_mtlLib = m_currentLine.Substr(m_currentLine.GetWordPosition(1)); m_mtlLib = m_currentLine.SubString(m_currentLine.GetWordPosition(1));
break; break;
case 'g': case 'g':
@ -251,7 +251,7 @@ bool NzOBJParser::Parse()
break; break;
} }
NzString objectName = m_currentLine.Substr(m_currentLine.GetWordPosition(1)); NzString objectName = m_currentLine.SubString(m_currentLine.GetWordPosition(1));
if (objectName.IsEmpty()) if (objectName.IsEmpty())
{ {
#if NAZARA_UTILITY_STRICT_RESOURCE_PARSING #if NAZARA_UTILITY_STRICT_RESOURCE_PARSING
@ -269,7 +269,7 @@ bool NzOBJParser::Parse()
#if NAZARA_UTILITY_STRICT_RESOURCE_PARSING #if NAZARA_UTILITY_STRICT_RESOURCE_PARSING
if (m_currentLine[1] == ' ') if (m_currentLine[1] == ' ')
{ {
NzString param = m_currentLine.Substr(2); NzString param = m_currentLine.SubString(2);
if (param != "all" && param != "on" && param != "off" && !param.IsNumber()) if (param != "all" && param != "on" && param != "off" && !param.IsNumber())
UnrecognizedLine(); UnrecognizedLine();
} }
@ -284,7 +284,7 @@ bool NzOBJParser::Parse()
UnrecognizedLine(); UnrecognizedLine();
#endif #endif
matName = m_currentLine.Substr(m_currentLine.GetWordPosition(1)); matName = m_currentLine.SubString(m_currentLine.GetWordPosition(1));
if (matName.IsEmpty()) if (matName.IsEmpty())
{ {
#if NAZARA_UTILITY_STRICT_RESOURCE_PARSING #if NAZARA_UTILITY_STRICT_RESOURCE_PARSING
@ -405,7 +405,7 @@ bool NzOBJParser::Advance(bool required)
m_lineCount++; m_lineCount++;
m_currentLine = m_stream.ReadLine(); m_currentLine = m_stream.ReadLine();
m_currentLine = m_currentLine.SubstrTo("#"); // On ignore les commentaires m_currentLine = m_currentLine.SubStringTo("#"); // On ignore les commentaires
m_currentLine.Simplify(); // Pour un traitement plus simple m_currentLine.Simplify(); // Pour un traitement plus simple
} }
while (m_currentLine.IsEmpty()); while (m_currentLine.IsEmpty());

View File

@ -215,7 +215,7 @@ bool NzMD5AnimParser::Parse(NzAnimation* animation)
sequence.firstFrame = 0; sequence.firstFrame = 0;
sequence.frameCount = m_frames.size(); sequence.frameCount = m_frames.size();
sequence.frameRate = m_frameRate; sequence.frameRate = m_frameRate;
sequence.name = m_stream.GetPath().SubstrFrom(NAZARA_DIRECTORY_SEPARATOR, -1, true); sequence.name = m_stream.GetPath().SubStringFrom(NAZARA_DIRECTORY_SEPARATOR, -1, true);
if (!animation->AddSequence(sequence)) if (!animation->AddSequence(sequence))
NazaraWarning("Failed to add sequence"); NazaraWarning("Failed to add sequence");
@ -265,7 +265,7 @@ bool NzMD5AnimParser::Advance(bool required)
m_lineCount++; m_lineCount++;
m_currentLine = m_stream.ReadLine(); m_currentLine = m_stream.ReadLine();
m_currentLine = m_currentLine.SubstrTo("//"); // On ignore les commentaires m_currentLine = m_currentLine.SubStringTo("//"); // On ignore les commentaires
m_currentLine.Simplify(); // Pour un traitement plus simple m_currentLine.Simplify(); // Pour un traitement plus simple
} }
while (m_currentLine.IsEmpty()); while (m_currentLine.IsEmpty());

View File

@ -390,7 +390,7 @@ bool NzMD5MeshParser::Advance(bool required)
m_lineCount++; m_lineCount++;
m_currentLine = m_stream.ReadLine(); m_currentLine = m_stream.ReadLine();
m_currentLine = m_currentLine.SubstrTo("//"); // On ignore les commentaires m_currentLine = m_currentLine.SubStringTo("//"); // On ignore les commentaires
m_currentLine.Simplify(); // Pour un traitement plus simple m_currentLine.Simplify(); // Pour un traitement plus simple
} }
while (m_currentLine.IsEmpty()); while (m_currentLine.IsEmpty());
@ -494,7 +494,7 @@ bool NzMD5MeshParser::ParseMesh()
} }
#endif #endif
m_meshes[m_meshIndex].shader = m_currentLine.Substr(7); m_meshes[m_meshIndex].shader = m_currentLine.SubString(7);
m_meshes[m_meshIndex].shader.Trim('"'); m_meshes[m_meshIndex].shader.Trim('"');
break; break;