void NString::Replace(NString strToReplace, NString strReplaceWith){ size_t position; int iLength = strToReplace.GetString().length(); position = m_strInfo.find(strToReplace.GetString()); while (position != std::string::npos){ m_strInfo.replace(position,iLength,strReplaceWith.GetString()); position = m_strInfo.find(strToReplace.GetString()); } }
int NString::Find(NString strSecondString){ size_t result; result = m_strInfo.find(strSecondString.GetString()); if (result != std::string::npos){ return (int)result; } return -1; }
NString operator+(const char* charlist, NString& strSecondString){ /* This is called for things like NString test2 = "hello"; NString test = "hi" + test2; (where the part comes first in the addition. Note that it is not a member of the NString class. */ std::string nestring = charlist + strSecondString.GetString(); NString newNString; newNString.SetString(nestring); return newNString; }
void NString::Format(NString strOriginal, int iNumber){ // Convert the number part into a string. std::stringstream stream; stream << iNumber; std::string strNumber = stream.str(); // Put the number into the main string, replacing the %d part. std::string strMain = strOriginal.GetString(); size_t position = strMain.find("%d"); strMain.replace(position,2,strNumber); m_strInfo = strMain; }
//============================================================================ // NFileUtilities::GetUniqueFile : Get a uniquely-named file. //---------------------------------------------------------------------------- NFile NFileUtilities::GetUniqueFile(const NFile &theDirectory, const NString &fileName) { NString nameChild, nameFile, nameExt; NRange extBreak; NFile theFile; NIndex n; // Validate our parameters NN_ASSERT(theDirectory.IsDirectory()); // Get the state we need if (fileName.IsEmpty()) { nameFile = "Temp"; nameExt = ".tmp"; } else { extBreak = fileName.Find(".", kNStringBackwards); if (extBreak.GetSize() == 1) { nameFile = fileName.GetLeft( extBreak.GetLocation()); nameExt = fileName.GetString(extBreak.GetLocation()); } else { nameFile = fileName; nameExt = ""; } } // Generate a unique name n = 0; while (n < 10000) { // Build the name if (n == 0) nameChild = nameFile; else nameChild.Format("%@ %ld", nameFile, n); if (!nameExt.IsEmpty()) nameChild += nameExt; // Check for the file theFile = theDirectory.GetChild(nameChild); if (!theFile.Exists()) return(theFile); n++; } // Handle failure NN_LOG("Unable to create a unique name"); theFile.Clear(); return(theFile); }
void NString::Append(const NString strSecondString){ m_strInfo.append(strSecondString.GetString()); }
void NString::operator=(const NString strSecondString){ m_strInfo = strSecondString.GetString(); }
bool NString::operator!=(NString& strSecondString){ if (m_strInfo != strSecondString.GetString()){ return true; } return false; }
NString NString::operator+(const NString strSecondString){ std::string nestring = m_strInfo + strSecondString.GetString(); NString newNString; newNString.SetString(nestring); return newNString; }