1
0
forked from 0ad/0ad

# Slightly tidied up string code.

CStr: Indented comments more consistently. Made some parameters
pass-by-reference, made some others not. Removed some useless methods -
Length (use length or empty), GetSubstring (use substr), LCase/UCase
(use LowerCase/UpperCase). Removed operator[] bounds-checking because
VS2005 does that anyway.
Maybe fixed noncopyable warnings on VS2003.

This was SVN commit r4828.
This commit is contained in:
Ykkrosh 2007-02-01 14:46:14 +00:00
parent fb91d32d61
commit 8d0a7170f6
39 changed files with 299 additions and 345 deletions

View File

@ -21,7 +21,7 @@ struct JSObject;
class CGameViewImpl; class CGameViewImpl;
class CGameView : private Scene class CGameView : private Scene, public boost::noncopyable
{ {
public: public:
static const float defaultFOV, defaultNear, defaultFar; static const float defaultFOV, defaultNear, defaultFar;

View File

@ -70,7 +70,7 @@ void CMapReader::LoadMap(const char* filename, CTerrain *pTerrain_,
if (unpacker.GetVersion() >= 3) { if (unpacker.GetVersion() >= 3) {
// read the corresponding XML file // read the corresponding XML file
filename_xml = filename; filename_xml = filename;
filename_xml = filename_xml.Left(filename_xml.Length()-4) + ".xml"; filename_xml = filename_xml.Left(filename_xml.length()-4) + ".xml";
RegMemFun(this, &CMapReader::ReadXML, L"CMapReader::ReadXML", 5800); RegMemFun(this, &CMapReader::ReadXML, L"CMapReader::ReadXML", 5800);
} }

View File

@ -52,7 +52,7 @@ void CMapWriter::SaveMap(const char* filename, CTerrain* pTerrain,
packer.Write(filename); packer.Write(filename);
CStr filename_xml (filename); CStr filename_xml (filename);
filename_xml = filename_xml.Left(filename_xml.Length()-4) + ".xml"; filename_xml = filename_xml.Left(filename_xml.length()-4) + ".xml";
WriteXML(filename_xml, pUnitMan, pWaterMan, pSkyMan, pLightEnv, pCamera, pCinema); WriteXML(filename_xml, pUnitMan, pWaterMan, pSkyMan, pLightEnv, pCamera, pCinema);
} }

View File

@ -21,13 +21,13 @@ static SMaterialColor ParseColor(CStr colorStr)
CStr tmp; CStr tmp;
int idx = 0; int idx = 0;
long pos = colorStr.Find(' '); long pos = colorStr.Find(' ');
while(colorStr.Length()) while(colorStr.length())
{ {
if(pos == -1) if(pos == -1)
pos = (long)colorStr.Length(); pos = (long)colorStr.length();
tmp = colorStr.GetSubstring(0, pos); tmp = colorStr.substr(0, pos);
colorStr = colorStr.GetSubstring(pos, colorStr.Length() - pos); colorStr = colorStr.substr(pos);
colorStr = colorStr.Trim(PS_TRIM_LEFT); colorStr = colorStr.Trim(PS_TRIM_LEFT);
pos = colorStr.Find(' '); pos = colorStr.Find(' ');
@ -80,10 +80,10 @@ static SMaterialColor ParseColor(CStr colorStr)
static bool ParseUsage(CStr temp) static bool ParseUsage(CStr temp)
{ {
temp = temp.LCase().Trim(PS_TRIM_BOTH); temp = temp.LowerCase().Trim(PS_TRIM_BOTH);
if(temp == CStr("blend") || if(temp == "blend" ||
temp == CStr("true") || temp == "true" ||
temp == CStr("yes") || temp == "yes" ||
temp.ToInt() > 0) temp.ToInt() > 0)
return true; return true;
@ -93,8 +93,8 @@ static bool ParseUsage(CStr temp)
#if 0 // unused #if 0 // unused
static GLenum ParseAlphaFunc(CStr temp) static GLenum ParseAlphaFunc(CStr temp)
{ {
temp = temp.LCase().Trim(PS_TRIM_BOTH); temp = temp.LowerCase().Trim(PS_TRIM_BOTH);
if(!temp.Length()) if(temp.empty())
return GL_NONE; return GL_NONE;
if(temp == CStr("never")) if(temp == CStr("never"))
@ -119,8 +119,8 @@ static GLenum ParseAlphaFunc(CStr temp)
static GLenum ParseBlendFunc(CStr temp) static GLenum ParseBlendFunc(CStr temp)
{ {
temp = temp.LCase().Trim(PS_TRIM_BOTH); temp = temp.LowerCase().Trim(PS_TRIM_BOTH);
if(!temp.Length()) if(temp.empty())
return GL_NONE; return GL_NONE;
if(temp == CStr("zero")) if(temp == CStr("zero"))
@ -232,19 +232,19 @@ CMaterial &CMaterialManager::LoadMaterial(const char *file)
else if(token == el_colors) else if(token == el_colors)
{ {
temp = (CStr)attrs.getNamedItem(at_diffuse); temp = (CStr)attrs.getNamedItem(at_diffuse);
if(temp.Length() > 0) if(! temp.empty())
material->SetDiffuse(ParseColor(temp)); material->SetDiffuse(ParseColor(temp));
temp = (CStr)attrs.getNamedItem(at_ambient); temp = (CStr)attrs.getNamedItem(at_ambient);
if(temp.Length() > 0) if(! temp.empty())
material->SetAmbient(ParseColor(temp)); material->SetAmbient(ParseColor(temp));
temp = (CStr)attrs.getNamedItem(at_specular); temp = (CStr)attrs.getNamedItem(at_specular);
if(temp.Length() > 0) if(! temp.empty())
material->SetSpecular(ParseColor(temp)); material->SetSpecular(ParseColor(temp));
temp = (CStr)attrs.getNamedItem(at_specularpower); temp = (CStr)attrs.getNamedItem(at_specularpower);
if(temp.Length() > 0) if(! temp.empty())
material->SetSpecularPower(ClampFloat(temp.ToFloat(), 0.0f, 1.0f)); material->SetSpecularPower(ClampFloat(temp.ToFloat(), 0.0f, 1.0f));
} }
else if(token == el_alpha) else if(token == el_alpha)

View File

@ -142,8 +142,8 @@ CModelDefPtr CMeshManager::GetMesh(const CStr& filename)
{ {
// Strip a three-letter file extension (if there is one) from the filename // Strip a three-letter file extension (if there is one) from the filename
CStr name; CStr name;
if (filename.Length() > 4 && filename[filename.Length()-4] == '.') if (filename.length() > 4 && filename[filename.length()-4] == '.')
name = filename.GetSubstring(0, filename.Length()-4); name = filename.substr(0, filename.length()-4);
else else
name = filename; name = filename;
@ -216,7 +216,7 @@ CModelDefPtr CMeshManager::GetMesh(const CStr& filename)
CStr cachedPmdVfsPath = "cache/"; CStr cachedPmdVfsPath = "cache/";
cachedPmdVfsPath += realDaePath; cachedPmdVfsPath += realDaePath;
// Remove the .dae extension (which will certainly be there) // Remove the .dae extension (which will certainly be there)
cachedPmdVfsPath = cachedPmdVfsPath.GetSubstring(0, cachedPmdVfsPath.Length()-4); cachedPmdVfsPath = cachedPmdVfsPath.substr(0, cachedPmdVfsPath.length()-4);
// Add a _hash.pmd extension // Add a _hash.pmd extension
cachedPmdVfsPath += "_"; cachedPmdVfsPath += "_";
cachedPmdVfsPath += hashString; cachedPmdVfsPath += hashString;

View File

@ -222,7 +222,8 @@ CSkeletonAnim* CModel::BuildAnimation(const char* filename, const char* name, fl
// Update: update this model by the given time, in seconds // Update: update this model by the given time, in seconds
void CModel::Update(float time) void CModel::Update(float time)
{ {
if (m_Anim && m_Anim->m_AnimDef && m_BoneMatrices) { if (m_Anim && m_Anim->m_AnimDef && m_BoneMatrices)
{
// adjust for animation speed // adjust for animation speed
float animtime = time*m_AnimSpeed; float animtime = time*m_AnimSpeed;
@ -234,11 +235,12 @@ void CModel::Update(float time)
float duration = m_Anim->m_AnimDef->GetDuration(); float duration = m_Anim->m_AnimDef->GetDuration();
if (m_AnimTime > duration) { if (m_AnimTime > duration)
{
if (m_Flags & MODELFLAG_NOLOOPANIMATION) if (m_Flags & MODELFLAG_NOLOOPANIMATION)
SetAnimation(m_NextAnim); SetAnimation(m_NextAnim);
else else
m_AnimTime = (float) fmod(m_AnimTime, duration); m_AnimTime = fmod(m_AnimTime, duration);
} }
// mark vertices as dirty // mark vertices as dirty
@ -249,11 +251,9 @@ void CModel::Update(float time)
} }
// update props // update props
for (uint i=0; i<m_Props.size(); i++) for (size_t i = 0; i < m_Props.size(); ++i)
{
m_Props[i].m_Model->Update(time); m_Props[i].m_Model->Update(time);
} }
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////
// InvalidatePosition // InvalidatePosition
@ -462,8 +462,9 @@ void CModel::SetTransform(const CMatrix3D& transform)
void CModel::SetMaterial(const CMaterial &material) void CModel::SetMaterial(const CMaterial &material)
{ {
m_Material = material; m_Material = material;
if(m_Material.GetTexture().Trim(PS_TRIM_BOTH).Length() > 0) if(m_Material.GetTexture().Trim(PS_TRIM_BOTH).length() > 0)
{ {
// [TODO: uh, shouldn't this be doing something?]
} }
} }

View File

@ -294,7 +294,7 @@ std::vector<u8> CObjectBase::CalculateVariationKey(const std::vector<std::set<CS
CObjectBase::Variant& var ((*grp)[match]); CObjectBase::Variant& var ((*grp)[match]);
for (std::vector<CObjectBase::Prop>::iterator it = var.m_Props.begin(); it != var.m_Props.end(); ++it) for (std::vector<CObjectBase::Prop>::iterator it = var.m_Props.begin(); it != var.m_Props.end(); ++it)
{ {
if (it->m_ModelName.Length()) if (! it->m_ModelName.empty())
chosenProps[it->m_PropPointName] = it->m_ModelName; chosenProps[it->m_PropPointName] = it->m_ModelName;
else else
chosenProps.erase(it->m_PropPointName); chosenProps.erase(it->m_PropPointName);
@ -347,18 +347,18 @@ const CObjectBase::Variation CObjectBase::BuildVariation(const std::vector<u8>&
// Apply its data: // Apply its data:
if (var.m_TextureFilename.Length()) if (! var.m_TextureFilename.empty())
variation.texture = var.m_TextureFilename; variation.texture = var.m_TextureFilename;
if (var.m_ModelFilename.Length()) if (! var.m_ModelFilename.empty())
variation.model = var.m_ModelFilename; variation.model = var.m_ModelFilename;
if (var.m_Color.Length()) if (! var.m_Color.empty())
variation.color = var.m_Color; variation.color = var.m_Color;
for (std::vector<CObjectBase::Prop>::iterator it = var.m_Props.begin(); it != var.m_Props.end(); ++it) for (std::vector<CObjectBase::Prop>::iterator it = var.m_Props.begin(); it != var.m_Props.end(); ++it)
{ {
if (it->m_ModelName.Length()) if (! it->m_ModelName.empty())
variation.props[it->m_PropPointName] = *it; variation.props[it->m_PropPointName] = *it;
else else
variation.props.erase(it->m_PropPointName); variation.props.erase(it->m_PropPointName);
@ -470,7 +470,7 @@ std::set<CStr> CObjectBase::CalculateRandomVariation(const std::set<CStr>& initi
CObjectBase::Variant& var ((*grp)[match]); CObjectBase::Variant& var ((*grp)[match]);
for (std::vector<CObjectBase::Prop>::iterator it = var.m_Props.begin(); it != var.m_Props.end(); ++it) for (std::vector<CObjectBase::Prop>::iterator it = var.m_Props.begin(); it != var.m_Props.end(); ++it)
{ {
if (it->m_ModelName.Length()) if (! it->m_ModelName.empty())
chosenProps[it->m_PropPointName] = it->m_ModelName; chosenProps[it->m_PropPointName] = it->m_ModelName;
else else
chosenProps.erase(it->m_PropPointName); chosenProps.erase(it->m_PropPointName);
@ -552,7 +552,7 @@ std::vector<std::vector<CStr> > CObjectBase::GetVariantGroups() const
const std::vector<Prop>& props = obj->m_VariantGroups[i][j].m_Props; const std::vector<Prop>& props = obj->m_VariantGroups[i][j].m_Props;
for (size_t k = 0; k < props.size(); ++k) for (size_t k = 0; k < props.size(); ++k)
{ {
if (props[k].m_ModelName.Length()) if (! props[k].m_ModelName.empty())
{ {
CObjectBase* prop = m_ObjectManager.FindObjectBase(props[k].m_ModelName); CObjectBase* prop = m_ObjectManager.FindObjectBase(props[k].m_ModelName);
if (prop) if (prop)

View File

@ -49,7 +49,7 @@ bool CObjectEntry::BuildVariation(const std::vector<std::set<CStr> >& selections
m_TextureName = variation.texture; m_TextureName = variation.texture;
m_ModelName = variation.model; m_ModelName = variation.model;
if (variation.color.Length()) if (! variation.color.empty())
{ {
std::stringstream str; std::stringstream str;
str << variation.color; str << variation.color;
@ -100,7 +100,7 @@ bool CObjectEntry::BuildVariation(const std::vector<std::set<CStr> >& selections
else if (name == "chop") name = "gather"; else if (name == "chop") name = "gather";
else if (name == "decay") name = "corpse"; else if (name == "decay") name = "corpse";
if (it->second.m_FileName.Length()) if (! it->second.m_FileName.empty())
{ {
CSkeletonAnim* anim = m_Model->BuildAnimation(it->second.m_FileName, name, it->second.m_Speed, it->second.m_ActionPos, it->second.m_ActionPos2); CSkeletonAnim* anim = m_Model->BuildAnimation(it->second.m_FileName, name, it->second.m_Speed, it->second.m_ActionPos, it->second.m_ActionPos2);
if (anim) if (anim)
@ -148,9 +148,9 @@ bool CObjectEntry::BuildVariation(const std::vector<std::set<CStr> >& selections
m_ProjectileModel = oe->m_Model; m_ProjectileModel = oe->m_Model;
} }
// Also the other special attachpoint 'loaded-<proppoint>' // Also the other special attachpoint 'loaded-<proppoint>'
else if( ( prop.m_PropPointName.Length() > 7 ) && ( prop.m_PropPointName.Left( 7 ) == "loaded-" ) ) else if (prop.m_PropPointName.length() > 7 && prop.m_PropPointName.Left(7) == "loaded-")
{ {
CStr ppn = prop.m_PropPointName.GetSubstring( 7, prop.m_PropPointName.Length() - 7 ); CStr ppn = prop.m_PropPointName.substr(7);
m_AmmunitionModel = oe->m_Model; m_AmmunitionModel = oe->m_Model;
m_AmmunitionPoint = modeldef->FindPropPoint((const char*)ppn ); m_AmmunitionPoint = modeldef->FindPropPoint((const char*)ppn );
if (! m_AmmunitionPoint) if (! m_AmmunitionPoint)

View File

@ -41,8 +41,8 @@ CTextureEntry::CTextureEntry(CTerrainPropertiesPtr props, const CStr& path):
else else
slashPos++; // Skip the actual slash slashPos++; // Skip the actual slash
if (dotPos == -1) if (dotPos == -1)
dotPos = (long)m_TexturePath.Length(); dotPos = (long)m_TexturePath.length();
m_Tag = m_TexturePath.GetSubstring(slashPos, dotPos-slashPos); m_Tag = m_TexturePath.substr(slashPos, dotPos-slashPos);
} }
///////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////

View File

@ -49,7 +49,7 @@ CTextureEntry* CTextureManager::FindTexture(CStr tag)
long pos=tag.ReverseFind("."); long pos=tag.ReverseFind(".");
if (pos != -1) if (pos != -1)
{ {
tag = tag.GetSubstring(0, pos); tag = tag.substr(0, pos);
} }
for (uint i=0;i<m_TextureEntries.size();i++) for (uint i=0;i<m_TextureEntries.size();i++)
{ {

View File

@ -50,7 +50,7 @@ void CButton::SetupText()
debug_assert(m_GeneratedTexts.size()>=1); debug_assert(m_GeneratedTexts.size()>=1);
CStr font; CStr font;
if (GUI<CStr>::GetSetting(this, "font", font) != PS_OK || font.Length()==0) if (GUI<CStr>::GetSetting(this, "font", font) != PS_OK || font.empty())
// Use the default if none is specified // Use the default if none is specified
// TODO Gee: (2004-08-14) Default should not be hard-coded, but be in styles! // TODO Gee: (2004-08-14) Default should not be hard-coded, but be in styles!
font = "default"; font = "default";

View File

@ -55,7 +55,7 @@ void CCheckBox::SetupText()
debug_assert(m_GeneratedTexts.size()>=1); debug_assert(m_GeneratedTexts.size()>=1);
CStr font; CStr font;
if (GUI<CStr>::GetSetting(this, "font", font) != PS_OK || font.Length()==0) if (GUI<CStr>::GetSetting(this, "font", font) != PS_OK || font.empty())
// Use the default if none is specified // Use the default if none is specified
// TODO Gee: (2004-08-14) Default should not be hard-coded, but be in styles! // TODO Gee: (2004-08-14) Default should not be hard-coded, but be in styles!
font = "default"; font = "default";

View File

@ -1243,7 +1243,7 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec
if (m_Styles.count("default") == 1) if (m_Styles.count("default") == 1)
object->LoadStyle(*this, "default"); object->LoadStyle(*this, "default");
if (argStyle.Length()) if (! argStyle.empty())
{ {
// additional check // additional check
if (m_Styles.count(argStyle) == 0) if (m_Styles.count(argStyle) == 0)
@ -1308,11 +1308,11 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec
} }
// Attempt to register the hotkey tag, if one was provided // Attempt to register the hotkey tag, if one was provided
if (hotkeyTag.Length()) if (! hotkeyTag.empty())
hotkeyRegisterGUIObject(object->GetName(), hotkeyTag); hotkeyRegisterGUIObject(object->GetName(), hotkeyTag);
CStrW caption (Element.getText()); CStrW caption (Element.getText());
if (caption.Length()) if (! caption.empty())
{ {
// Set the setting caption to this // Set the setting caption to this
object->SetSetting("caption", caption, true); object->SetSetting("caption", caption, true);
@ -1351,7 +1351,7 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec
CStr code; CStr code;
// If there is a file, open it and use it as the code // If there is a file, open it and use it as the code
if (file.Length()) if (! file.empty())
{ {
CVFSFile scriptfile; CVFSFile scriptfile;
if (scriptfile.Load(file) != PSRETURN_OK) if (scriptfile.Load(file) != PSRETURN_OK)
@ -1434,13 +1434,13 @@ void CGUI::Xeromyces_ReadScript(XMBElement Element, CXeromyces* pFile)
CStr file (Element.getAttributes().getNamedItem( pFile->getAttributeID("file") )); CStr file (Element.getAttributes().getNamedItem( pFile->getAttributeID("file") ));
// If there is a file specified, open and execute it // If there is a file specified, open and execute it
if (file.Length()) if (! file.empty())
g_ScriptingHost.RunScript(file, m_ScriptObject); g_ScriptingHost.RunScript(file, m_ScriptObject);
// Execute inline scripts // Execute inline scripts
CStr code (Element.getText()); CStr code (Element.getText());
if (code.Length()) if (! code.empty())
g_ScriptingHost.RunMemScript(code.c_str(), code.Length(), "Some XML file", Element.getLineNumber(), m_ScriptObject); g_ScriptingHost.RunMemScript(code.c_str(), code.length(), "Some XML file", Element.getLineNumber(), m_ScriptObject);
} }
void CGUI::Xeromyces_ReadSprite(XMBElement Element, CXeromyces* pFile) void CGUI::Xeromyces_ReadSprite(XMBElement Element, CXeromyces* pFile)
@ -1878,7 +1878,7 @@ void CGUI::Xeromyces_ReadColor(XMBElement Element, CXeromyces* pFile)
// Try parsing value // Try parsing value
CStr value (Element.getText()); CStr value (Element.getText());
if (value.Length()) if (! value.empty())
{ {
// Try setting color to value // Try setting color to value
if (!color.ParseString(value, 255.f)) if (!color.ParseString(value, 255.f))

View File

@ -68,11 +68,11 @@ InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev)
wchar_t* text = sys_clipboard_get(); wchar_t* text = sys_clipboard_get();
if (text) if (text)
{ {
if (m_iBufferPos == (int)pCaption->Length()) if (m_iBufferPos == (int)pCaption->length())
*pCaption += text; *pCaption += text;
else else
*pCaption = pCaption->Left(m_iBufferPos) + text + *pCaption = pCaption->Left(m_iBufferPos) + text +
pCaption->Right((long) pCaption->Length()-m_iBufferPos); pCaption->Right((long) pCaption->length()-m_iBufferPos);
UpdateText(m_iBufferPos, m_iBufferPos, m_iBufferPos+1); UpdateText(m_iBufferPos, m_iBufferPos, m_iBufferPos+1);
@ -105,15 +105,15 @@ InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev)
{ {
m_iBufferPos_Tail = -1; m_iBufferPos_Tail = -1;
if (pCaption->Length() == 0 || if (pCaption->empty() ||
m_iBufferPos == 0) m_iBufferPos == 0)
break; break;
if (m_iBufferPos == (int)pCaption->Length()) if (m_iBufferPos == (int)pCaption->length())
*pCaption = pCaption->Left( (long) pCaption->Length()-1); *pCaption = pCaption->Left( (long) pCaption->length()-1);
else else
*pCaption = pCaption->Left( m_iBufferPos-1 ) + *pCaption = pCaption->Left( m_iBufferPos-1 ) +
pCaption->Right( (long) pCaption->Length()-m_iBufferPos ); pCaption->Right( (long) pCaption->length()-m_iBufferPos );
UpdateText(m_iBufferPos-1, m_iBufferPos, m_iBufferPos-1); UpdateText(m_iBufferPos-1, m_iBufferPos, m_iBufferPos-1);
@ -132,12 +132,12 @@ InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev)
} }
else else
{ {
if (pCaption->Length() == 0 || if (pCaption->empty() ||
m_iBufferPos == (int)pCaption->Length()) m_iBufferPos == (int)pCaption->length())
break; break;
*pCaption = pCaption->Left( m_iBufferPos ) + *pCaption = pCaption->Left( m_iBufferPos ) +
pCaption->Right( (long) pCaption->Length()-(m_iBufferPos+1) ); pCaption->Right( (long) pCaption->length()-(m_iBufferPos+1) );
UpdateText(m_iBufferPos, m_iBufferPos+1, m_iBufferPos); UpdateText(m_iBufferPos, m_iBufferPos+1, m_iBufferPos);
} }
@ -177,7 +177,7 @@ InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev)
m_iBufferPos_Tail = m_iBufferPos; m_iBufferPos_Tail = m_iBufferPos;
} }
m_iBufferPos = (long) pCaption->Length(); m_iBufferPos = (long) pCaption->length();
m_WantedX=0.f; m_WantedX=0.f;
UpdateAutoScroll(); UpdateAutoScroll();
@ -257,7 +257,7 @@ InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev)
} }
if (m_iBufferPos != (int)pCaption->Length()) if (m_iBufferPos != (int)pCaption->length())
++m_iBufferPos; ++m_iBufferPos;
} }
else else
@ -417,7 +417,7 @@ InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev)
// check max length // check max length
int max_length; int max_length;
GUI<int>::GetSetting(this, "max_length", max_length); GUI<int>::GetSetting(this, "max_length", max_length);
if (max_length != 0 && (int)pCaption->Length() >= max_length) if (max_length != 0 && (int)pCaption->length() >= max_length)
break; break;
m_WantedX=0.f; m_WantedX=0.f;
@ -426,11 +426,11 @@ InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev)
DeleteCurSelection(); DeleteCurSelection();
m_iBufferPos_Tail = -1; m_iBufferPos_Tail = -1;
if (m_iBufferPos == (int)pCaption->Length()) if (m_iBufferPos == (int)pCaption->length())
*pCaption += cooked; *pCaption += cooked;
else else
*pCaption = pCaption->Left(m_iBufferPos) + CStrW(cooked) + *pCaption = pCaption->Left(m_iBufferPos) + CStrW(cooked) +
pCaption->Right((long) pCaption->Length()-m_iBufferPos); pCaption->Right((long) pCaption->length()-m_iBufferPos);
UpdateText(m_iBufferPos, m_iBufferPos, m_iBufferPos+1); UpdateText(m_iBufferPos, m_iBufferPos, m_iBufferPos+1);
@ -1029,7 +1029,7 @@ void CInput::UpdateText(int from, int to_before, int to_after)
int to = 0; // make sure it's initialized int to = 0; // make sure it's initialized
if (to_before == -1) if (to_before == -1)
to = (int)caption.Length(); to = (int)caption.length();
CFont font(font_name); CFont font(font_name);
@ -1143,7 +1143,7 @@ void CInput::UpdateText(int from, int to_before, int to_after)
if (destroy_row_to != m_CharacterPositions.end()) if (destroy_row_to != m_CharacterPositions.end())
to = destroy_row_to->m_ListStart; // notice it will iterate [from, to), so it will never reach to. to = destroy_row_to->m_ListStart; // notice it will iterate [from, to), so it will never reach to.
else else
to = (int)caption.Length(); to = (int)caption.length();
// Setup the first row // Setup the first row
@ -1157,7 +1157,7 @@ void CInput::UpdateText(int from, int to_before, int to_after)
list<SRow>::iterator temp_it = destroy_row_to; list<SRow>::iterator temp_it = destroy_row_to;
--temp_it; --temp_it;
CStr c_caption1(caption.GetSubstring(destroy_row_from->m_ListStart, (temp_it->m_ListStart + temp_it->m_ListOfX.size()) -destroy_row_from->m_ListStart)); CStr c_caption1(caption.substr(destroy_row_from->m_ListStart, (temp_it->m_ListStart + temp_it->m_ListOfX.size()) -destroy_row_from->m_ListStart));
m_CharacterPositions.erase(destroy_row_from, destroy_row_to); m_CharacterPositions.erase(destroy_row_from, destroy_row_to);
@ -1179,7 +1179,7 @@ void CInput::UpdateText(int from, int to_before, int to_after)
check_point_row_start += delta; check_point_row_start += delta;
check_point_row_end += delta; check_point_row_end += delta;
if (to != (int)caption.Length()) if (to != (int)caption.length())
to += delta; to += delta;
} }
} }
@ -1195,10 +1195,10 @@ void CInput::UpdateText(int from, int to_before, int to_after)
{ {
if (caption[i] == L'\n' && multiline) if (caption[i] == L'\n' && multiline)
{ {
if (i==to-1 && to != (int)caption.Length()) if (i==to-1 && to != (int)caption.length())
break; // it will be added outside break; // it will be added outside
CStr c_caption1(caption.GetSubstring(row.m_ListStart, row.m_ListOfX.size())); CStr c_caption1(caption.substr(row.m_ListStart, row.m_ListOfX.size()));
current_line = m_CharacterPositions.insert( current_line, row ); current_line = m_CharacterPositions.insert( current_line, row );
++current_line; ++current_line;
@ -1241,7 +1241,7 @@ void CInput::UpdateText(int from, int to_before, int to_after)
// both before and after that character, being on different // both before and after that character, being on different
// rows. With automatic word-wrapping, that is not possible. Which // rows. With automatic word-wrapping, that is not possible. Which
// is intuitively correct. // is intuitively correct.
CStr c_caption1(caption.GetSubstring(row.m_ListStart, row.m_ListOfX.size())); CStr c_caption1(caption.substr(row.m_ListStart, row.m_ListOfX.size()));
current_line = m_CharacterPositions.insert( current_line, row ); current_line = m_CharacterPositions.insert( current_line, row );
++current_line; ++current_line;
@ -1348,7 +1348,7 @@ void CInput::UpdateText(int from, int to_before, int to_after)
if (destroy_row_to != m_CharacterPositions.end()) if (destroy_row_to != m_CharacterPositions.end())
to = destroy_row_to->m_ListStart; // notice it will iterate [from, to[, so it will never reach to. to = destroy_row_to->m_ListStart; // notice it will iterate [from, to[, so it will never reach to.
else else
to = (int)caption.Length(); to = (int)caption.length();
// Set current line, new rows will be added before current_line, so // Set current line, new rows will be added before current_line, so
@ -1366,7 +1366,7 @@ void CInput::UpdateText(int from, int to_before, int to_after)
m_CharacterPositions.erase(destroy_row_from, destroy_row_to); m_CharacterPositions.erase(destroy_row_from, destroy_row_to);
CStr c_caption(caption.GetSubstring(from, to-from)); CStr c_caption(caption.substr(from, to-from));
} }
// else, the for loop will end naturally. // else, the for loop will end naturally.
} }
@ -1527,7 +1527,7 @@ void CInput::DeleteCurSelection()
} }
*pCaption = pCaption->Left( VirtualFrom ) + *pCaption = pCaption->Left( VirtualFrom ) +
pCaption->Right( (long) pCaption->Length()-(VirtualTo) ); pCaption->Right( (long) pCaption->length()-(VirtualTo) );
UpdateText(VirtualFrom, VirtualTo, VirtualFrom); UpdateText(VirtualFrom, VirtualTo, VirtualFrom);

View File

@ -78,7 +78,7 @@ void CList::SetupText()
m_GeneratedTexts.clear(); m_GeneratedTexts.clear();
CStr font; CStr font;
if (GUI<CStr>::GetSetting(this, "font", font) != PS_OK || font.Length()==0) if (GUI<CStr>::GetSetting(this, "font", font) != PS_OK || font.empty())
// Use the default if none is specified // Use the default if none is specified
// TODO Gee: (2004-08-14) Don't define standard like this. Do it with the default style. // TODO Gee: (2004-08-14) Don't define standard like this. Do it with the default style.
font = "default"; font = "default";

View File

@ -55,7 +55,7 @@ void CText::SetupText()
debug_assert(m_GeneratedTexts.size()>=1); debug_assert(m_GeneratedTexts.size()>=1);
CStr font; CStr font;
if (GUI<CStr>::GetSetting(this, "font", font) != PS_OK || font.Length()==0) if (GUI<CStr>::GetSetting(this, "font", font) != PS_OK || font.empty())
// Use the default if none is specified // Use the default if none is specified
// TODO Gee: (2004-08-14) Don't define standard like this. Do it with the default style. // TODO Gee: (2004-08-14) Don't define standard like this. Do it with the default style.
font = "default"; font = "default";

View File

@ -48,7 +48,7 @@ void CTooltip::SetupText()
debug_assert(m_GeneratedTexts.size()==1); debug_assert(m_GeneratedTexts.size()==1);
CStr font; CStr font;
if (GUI<CStr>::GetSetting(this, "font", font) != PS_OK || font.Length()==0) if (GUI<CStr>::GetSetting(this, "font", font) != PS_OK || font.empty())
font = "default"; font = "default";
float buffer_zone = 0.f; float buffer_zone = 0.f;

View File

@ -386,7 +386,7 @@ void GUIRenderer::UpdateDrawCallCache(DrawCalls &Calls, CStr& SpriteName, CRect
Call.m_Vertices = ObjectSize; Call.m_Vertices = ObjectSize;
if (cit->m_TextureName.Length()) if (! cit->m_TextureName.empty())
{ {
Handle h = ogl_tex_load(cit->m_TextureName); Handle h = ogl_tex_load(cit->m_TextureName);
if (h <= 0) if (h <= 0)

View File

@ -72,13 +72,13 @@ static bool GetTooltip(IGUIObject* obj, CStr&style)
CStr text; CStr text;
if (GUI<CStr>::GetSetting(obj, "tooltip", text) == PS_OK) if (GUI<CStr>::GetSetting(obj, "tooltip", text) == PS_OK)
{ {
if (text.Length() == 0) if (text.empty())
{ {
// No tooltip // No tooltip
return false; return false;
} }
if (style.Length() == 0) if (style.empty())
// Text, but no style - use default // Text, but no style - use default
style = "default"; style = "default";
@ -94,7 +94,7 @@ void GUITooltip::ShowTooltip(IGUIObject* obj, CPos pos, const CStr& style, CGUI*
debug_assert(obj); debug_assert(obj);
// Ignore attempts to use tooltip "" // Ignore attempts to use tooltip ""
if (style.Length() == 0) if (style.empty())
return; return;
// Get the object referenced by 'tooltip_style' // Get the object referenced by 'tooltip_style'
@ -109,7 +109,7 @@ void GUITooltip::ShowTooltip(IGUIObject* obj, CPos pos, const CStr& style, CGUI*
CStr usedObjectName; CStr usedObjectName;
if (GUI<CStr>::GetSetting(tooltipobj, "use_object", usedObjectName) == PS_OK if (GUI<CStr>::GetSetting(tooltipobj, "use_object", usedObjectName) == PS_OK
&& usedObjectName.Length()) && !usedObjectName.empty())
{ {
usedobj = gui->FindObjectByName(usedObjectName); usedobj = gui->FindObjectByName(usedObjectName);
if (! usedobj) if (! usedobj)
@ -151,7 +151,7 @@ void GUITooltip::ShowTooltip(IGUIObject* obj, CPos pos, const CStr& style, CGUI*
void GUITooltip::HideTooltip(const CStr& style, CGUI* gui) void GUITooltip::HideTooltip(const CStr& style, CGUI* gui)
{ {
// Ignore attempts to use tooltip "" // Ignore attempts to use tooltip ""
if (style.Length() == 0) if (style.empty())
return; return;
IGUIObject* tooltipobj = gui->FindObjectByName("__tooltip_"+style); IGUIObject* tooltipobj = gui->FindObjectByName("__tooltip_"+style);
@ -163,7 +163,7 @@ void GUITooltip::HideTooltip(const CStr& style, CGUI* gui)
CStr usedObjectName; CStr usedObjectName;
if (GUI<CStr>::GetSetting(tooltipobj, "use_object", usedObjectName) == PS_OK if (GUI<CStr>::GetSetting(tooltipobj, "use_object", usedObjectName) == PS_OK
&& usedObjectName.Length()) && !usedObjectName.empty())
{ {
IGUIObject* usedobj = gui->FindObjectByName(usedObjectName); IGUIObject* usedobj = gui->FindObjectByName(usedObjectName);
if (! usedobj) if (! usedobj)

View File

@ -180,7 +180,7 @@ void CGUIString::GenerateTextCall(SFeedback &Feedback,
TextCall.m_UseCustomColor = false; TextCall.m_UseCustomColor = false;
// Extract substring from RawString. // Extract substring from RawString.
TextCall.m_String = GetRawString().GetSubstring(_from, _to-_from); TextCall.m_String = GetRawString().substr(_from, _to-_from);
// Go through tags and apply changes. // Go through tags and apply changes.
vector<CGUIString::TextChunk::Tag>::const_iterator it2; vector<CGUIString::TextChunk::Tag>::const_iterator it2;
@ -226,7 +226,7 @@ void CGUIString::GenerateTextCall(SFeedback &Feedback,
// These are also needed later // These are also needed later
TextCall.m_Size = size; TextCall.m_Size = size;
if (TextCall.m_String.Length() >= 1) if (! TextCall.m_String.empty())
{ {
if (TextCall.m_String[0] == '\n') if (TextCall.m_String[0] == '\n')
{ {
@ -320,12 +320,12 @@ void CGUIString::SetValue(const CStrW& str)
if (curpos == -1) if (curpos == -1)
{ {
m_RawString += str.GetSubstring(position, str.Length()-position); m_RawString += str.substr(position);
if (from != (long)m_RawString.Length()) if (from != (long)m_RawString.length())
{ {
CurrentTextChunk.m_From = from; CurrentTextChunk.m_From = from;
CurrentTextChunk.m_To = (int)m_RawString.Length(); CurrentTextChunk.m_To = (int)m_RawString.length();
m_TextChunks.push_back(CurrentTextChunk); m_TextChunks.push_back(CurrentTextChunk);
} }
@ -340,23 +340,23 @@ void CGUIString::SetValue(const CStrW& str)
if (pos_right == -1) if (pos_right == -1)
{ {
m_RawString += str.GetSubstring(position, curpos-position+1); m_RawString += str.substr(position, curpos-position+1);
continue; continue;
} }
else else
if (pos_left != -1 && pos_left < pos_right) if (pos_left != -1 && pos_left < pos_right)
{ {
m_RawString += str.GetSubstring(position, pos_left-position); m_RawString += str.substr(position, pos_left-position);
continue; continue;
} }
else else
{ {
m_RawString += str.GetSubstring(position, curpos-position); m_RawString += str.substr(position, curpos-position);
// Okay we've found a TagStart and TagEnd, positioned // Okay we've found a TagStart and TagEnd, positioned
// at pos and pos_right. Now let's extract the // at pos and pos_right. Now let's extract the
// interior and try parsing. // interior and try parsing.
CStr tagstr = str.GetSubstring(curpos+1, pos_right-curpos-1); CStr tagstr = str.substr(curpos+1, pos_right-curpos-1);
CParserLine Line; CParserLine Line;
Line.ParseString(Parser, (const char*)tagstr); Line.ParseString(Parser, (const char*)tagstr);
@ -493,7 +493,7 @@ void CGUIString::SetValue(const CStrW& str)
{ {
// What was within the tags could not be interpreted // What was within the tags could not be interpreted
// so we'll assume it's just text. // so we'll assume it's just text.
m_RawString += str.GetSubstring(curpos, pos_right-curpos+1); m_RawString += str.substr(curpos, pos_right-curpos+1);
} }
curpos = pos_right; curpos = pos_right;
@ -508,7 +508,7 @@ void CGUIString::SetValue(const CStrW& str)
// those cases. // those cases.
// We'll sort later. // We'll sort later.
m_Words.push_back(0); m_Words.push_back(0);
m_Words.push_back((int)m_RawString.Length()); m_Words.push_back((int)m_RawString.length());
// Space: ' ' // Space: ' '
for (position=0, curpos=0;;position = curpos+1) for (position=0, curpos=0;;position = curpos+1)

View File

@ -130,7 +130,7 @@ void IGUIObject::AddToPointersMap(map_pObjects &ObjectMap)
// Now actually add this one // Now actually add this one
// notice we won't add it if it's doesn't have any parent // notice we won't add it if it's doesn't have any parent
// (i.e. being the base object) // (i.e. being the base object)
if (m_Name.Length() == 0) if (m_Name.empty())
{ {
throw PS_NEEDS_NAME; throw PS_NEEDS_NAME;
} }
@ -428,7 +428,8 @@ void IGUIObject::RegisterScriptHandler(const CStr& Action, const CStr& Code, CGU
char buf[64]; char buf[64];
sprintf(buf, "__eventhandler%d", x++); sprintf(buf, "__eventhandler%d", x++);
JSFunction* func = JS_CompileFunction(g_ScriptingHost.getContext(), pGUI->m_ScriptObject, buf, paramCount, paramNames, (const char*)Code, Code.Length(), CodeName, 0); JSFunction* func = JS_CompileFunction(g_ScriptingHost.getContext(), pGUI->m_ScriptObject,
buf, paramCount, paramNames, (const char*)Code, Code.length(), CodeName, 0);
debug_assert(func); // TODO: Handle errors debug_assert(func); // TODO: Handle errors
if (func) if (func)
SetScriptHandler(Action, JS_GetFunctionObject(func)); SetScriptHandler(Action, JS_GetFunctionObject(func));
@ -500,10 +501,10 @@ CStr IGUIObject::GetPresentableName() const
{ {
// __internal(), must be at least 13 letters to be able to be // __internal(), must be at least 13 letters to be able to be
// an internal name // an internal name
if (m_Name.Length() <= 12) if (m_Name.length() <= 12)
return m_Name; return m_Name;
if (m_Name.GetSubstring(0, 10) == "__internal") if (m_Name.substr(0, 10) == "__internal")
return CStr("[unnamed object]"); return CStr("[unnamed object]");
else else
return m_Name; return m_Name;

View File

@ -19,7 +19,7 @@ namespace I18n
{ {
class CLocale; class CLocale;
class TSComponent : boost::noncopyable class TSComponent
{ {
public: public:
virtual const StrImW ToString(CLocale* locale, std::vector<BufferVariable*>& vars) const = 0; virtual const StrImW ToString(CLocale* locale, std::vector<BufferVariable*>& vars) const = 0;
@ -27,9 +27,10 @@ namespace I18n
}; };
class TSComponentString : public TSComponent { class TSComponentString : public TSComponent, boost::noncopyable
{
public: public:
TSComponentString(const wchar_t* s) : String(s) {}; TSComponentString(const wchar_t* s) : String(s) {}
const StrImW ToString(CLocale* locale, std::vector<BufferVariable*>& vars) const; const StrImW ToString(CLocale* locale, std::vector<BufferVariable*>& vars) const;
@ -38,9 +39,10 @@ namespace I18n
}; };
class TSComponentVariable : public TSComponent { class TSComponentVariable : public TSComponent, boost::noncopyable
{
public: public:
TSComponentVariable(unsigned char id) : ID(id) {}; TSComponentVariable(unsigned char id) : ID(id) {}
const StrImW ToString(CLocale* locale, std::vector<BufferVariable*>& vars) const; const StrImW ToString(CLocale* locale, std::vector<BufferVariable*>& vars) const;
@ -49,10 +51,10 @@ namespace I18n
}; };
class TSComponentFunction : public TSComponent, boost::noncopyable
class TSComponentFunction : public TSComponent { {
public: public:
TSComponentFunction(const char* name) : Name(name) {}; TSComponentFunction(const char* name) : Name(name) {}
~TSComponentFunction(); ~TSComponentFunction();
const StrImW ToString(CLocale* locale, std::vector<BufferVariable*>& vars) const; const StrImW ToString(CLocale* locale, std::vector<BufferVariable*>& vars) const;
@ -67,7 +69,6 @@ namespace I18n
}; };
} }
#endif // I18N_TSCOMPONENT_H #endif // I18N_TSCOMPONENT_H

View File

@ -257,7 +257,7 @@ static LibError do_load_shader(
CStr Type = Shader.getAttributes().getNamedItem(at_type); CStr Type = Shader.getAttributes().getNamedItem(at_type);
if (!Type.Length()) if (Type.empty())
{ {
LOG(ERROR, LOG_CATEGORY, "%hs: Missing attribute \"type\" in element \"Shader\".", LOG(ERROR, LOG_CATEGORY, "%hs: Missing attribute \"type\" in element \"Shader\".",
filename); filename);
@ -275,7 +275,7 @@ static LibError do_load_shader(
CStr Name = Shader.getText(); CStr Name = Shader.getText();
if (!Name.Length()) if (Name.empty())
{ {
LOG(ERROR, LOG_CATEGORY, "%hs: Missing shader name.", filename); LOG(ERROR, LOG_CATEGORY, "%hs: Missing shader name.", filename);
WARN_RETURN(ERR::CORRUPTED); WARN_RETURN(ERR::CORRUPTED);

View File

@ -319,9 +319,9 @@ CStr _nm::GetStringRaw() const \
#define NMT_END_ARRAY() \ #define NMT_END_ARRAY() \
++it; \ ++it; \
ret=ret.GetSubstring(0, ret.Length()-2)+_T(" }, "); \ ret=ret.substr(0, ret.length()-2)+_T(" }, "); \
} \ } \
ret=ret.GetSubstring(0, ret.Length()-2)+_T(" }, "); ret=ret.substr(0, ret.length()-2)+_T(" }, ");
#define NMT_FIELD_INT(_nm, _hosttp, _netsz) \ #define NMT_FIELD_INT(_nm, _hosttp, _netsz) \
ret += #_nm _T(": "); \ ret += #_nm _T(": "); \
@ -334,7 +334,7 @@ CStr _nm::GetStringRaw() const \
ret += _T(", "); ret += _T(", ");
#define END_NMT_CLASS() \ #define END_NMT_CLASS() \
return ret.GetSubstring(0, ret.Length()-2); \ return ret.substr(0, ret.length()-2); \
} }
#include "NMTCreator.h" #include "NMTCreator.h"

View File

@ -719,9 +719,9 @@ void CConsole::LoadHistory()
{ {
if (pos > 0) if (pos > 0)
m_deqBufHistory.push_front(str.Left(str[pos-1] == '\r' ? pos - 1 : pos)); m_deqBufHistory.push_front(str.Left(str[pos-1] == '\r' ? pos - 1 : pos));
str = str.GetSubstring( pos + 1, str.npos ); str = str.substr(pos + 1);
} }
else if( str.Length() > 0 ) else if (str.length() > 0)
m_deqBufHistory.push_front(str); m_deqBufHistory.push_front(str);
} }
} }
@ -737,7 +737,7 @@ void CConsole::SaveHistory()
break; break;
buffer = CStrW(*it).ToUTF8() + "\n" + buffer; buffer = CStrW(*it).ToUTF8() + "\n" + buffer;
} }
vfs_store( m_sHistoryFile, (const void*)buffer.c_str(), buffer.Length(), FILE_NO_AIO ); vfs_store(m_sHistoryFile, (const void*)buffer.c_str(), buffer.length(), FILE_NO_AIO);
} }
void CConsole::SendChatMessage(const wchar_t *szMessage) void CConsole::SendChatMessage(const wchar_t *szMessage)

View File

@ -195,7 +195,7 @@ CStrW CStr8::FromUTF8() const
CStr CStr::Repeat(const CStr& String, size_t Reps) CStr CStr::Repeat(const CStr& String, size_t Reps)
{ {
CStr ret; CStr ret;
ret.reserve(String.Length() * Reps); ret.reserve(String.length() * Reps);
while (Reps--) ret += String; while (Reps--) ret += String;
return ret; return ret;
} }
@ -259,12 +259,6 @@ double CStr::ToDouble() const
return _tstod(c_str(), NULL); return _tstod(c_str(), NULL);
} }
// Retrieves at most 'len' characters, starting at 'start'
CStr CStr::GetSubstring(size_t start, size_t len) const
{
return substr(start, len);
}
// Search the string for another string // Search the string for another string
long CStr::Find(const CStr& Str) const long CStr::Find(const CStr& Str) const
@ -278,7 +272,7 @@ long CStr::Find(const CStr& Str) const
} }
// Search the string for another string // Search the string for another string
long CStr::Find(const tchar &chr) const long CStr::Find(const tchar chr) const
{ {
size_t Pos = find(chr, 0); size_t Pos = find(chr, 0);
@ -289,7 +283,7 @@ long CStr::Find(const tchar &chr) const
} }
// Search the string for another string // Search the string for another string
long CStr::Find(const int &start, const tchar &chr) const long CStr::Find(const int start, const tchar chr) const
{ {
size_t Pos = find(chr, start); size_t Pos = find(chr, start);
@ -299,9 +293,9 @@ long CStr::Find(const int &start, const tchar &chr) const
return -1; return -1;
} }
long CStr::FindInsensitive(const int &start, const tchar &chr) const { return LCase().Find(start, _totlower(chr)); } long CStr::FindInsensitive(const int start, const tchar chr) const { return LowerCase().Find(start, _totlower(chr)); }
long CStr::FindInsensitive(const tchar &chr) const { return LCase().Find(_totlower(chr)); } long CStr::FindInsensitive(const tchar chr) const { return LowerCase().Find(_totlower(chr)); }
long CStr::FindInsensitive(const CStr& Str) const { return LCase().Find(Str.LCase()); } long CStr::FindInsensitive(const CStr& Str) const { return LowerCase().Find(Str.LowerCase()); }
long CStr::ReverseFind(const CStr& Str) const long CStr::ReverseFind(const CStr& Str) const
@ -334,25 +328,6 @@ CStr CStr::UpperCase() const
return NewString; return NewString;
} }
// Lazy versions
// code duplication because return by value overhead if they were merely an alias
CStr CStr::LCase() const
{
std::tstring NewString = *this;
for (size_t i = 0; i < length(); i++)
NewString[i] = (tchar)_totlower((*this)[i]);
return NewString;
}
CStr CStr::UCase() const
{
std::tstring NewString = *this;
for (size_t i = 0; i < length(); i++)
NewString[i] = (tchar)_totupper((*this)[i]);
return NewString;
}
// Retrieve the substring of the first n characters // Retrieve the substring of the first n characters
CStr CStr::Left(size_t len) const CStr CStr::Left(size_t len) const
@ -370,10 +345,10 @@ CStr CStr::Right(size_t len) const
// Retrieve the substring following the last occurrence of Str // Retrieve the substring following the last occurrence of Str
// (or the whole string if it doesn't contain Str) // (or the whole string if it doesn't contain Str)
CStr CStr::AfterLast(const CStr& Str) const CStr CStr::AfterLast(const CStr& Str, size_t startPos) const
{ {
long pos = ReverseFind(Str); size_t pos = rfind(Str, startPos);
if (pos == -1) if (pos == npos)
return *this; return *this;
else else
return substr(pos + Str.length()); return substr(pos + Str.length());
@ -381,10 +356,10 @@ CStr CStr::AfterLast(const CStr& Str) const
// Retrieve the substring preceding the last occurrence of Str // Retrieve the substring preceding the last occurrence of Str
// (or the whole string if it doesn't contain Str) // (or the whole string if it doesn't contain Str)
CStr CStr::BeforeLast(const CStr& Str) const CStr CStr::BeforeLast(const CStr& Str, size_t startPos) const
{ {
long pos = ReverseFind(Str); size_t pos = rfind(Str, startPos);
if (pos == -1) if (pos == npos)
return *this; return *this;
else else
return substr(0, pos); return substr(0, pos);
@ -392,10 +367,10 @@ CStr CStr::BeforeLast(const CStr& Str) const
// Retrieve the substring following the first occurrence of Str // Retrieve the substring following the first occurrence of Str
// (or the whole string if it doesn't contain Str) // (or the whole string if it doesn't contain Str)
CStr CStr::AfterFirst(const CStr& Str) const CStr CStr::AfterFirst(const CStr& Str, size_t startPos) const
{ {
long pos = Find(Str); size_t pos = find(Str, startPos);
if (pos == -1) if (pos == npos)
return *this; return *this;
else else
return substr(pos + Str.length()); return substr(pos + Str.length());
@ -403,10 +378,10 @@ CStr CStr::AfterFirst(const CStr& Str) const
// Retrieve the substring preceding the first occurrence of Str // Retrieve the substring preceding the first occurrence of Str
// (or the whole string if it doesn't contain Str) // (or the whole string if it doesn't contain Str)
CStr CStr::BeforeFirst(const CStr& Str) const CStr CStr::BeforeFirst(const CStr& Str, size_t startPos) const
{ {
long pos = Find(Str); size_t pos = find(Str, startPos);
if (pos == -1) if (pos == npos)
return *this; return *this;
else else
return substr(0, pos); return substr(0, pos);
@ -442,7 +417,7 @@ void CStr::Replace(const CStr& ToReplace, const CStr& ReplaceWith)
} }
} }
CStr CStr::UnescapeBackslashes() CStr CStr::UnescapeBackslashes() const
{ {
// Currently only handle \n and \\, because they're the only interesting ones // Currently only handle \n and \\, because they're the only interesting ones
CStr NewString; CStr NewString;

View File

@ -24,10 +24,10 @@ Examples:
*/ */
// history: // history:
// 19 May 04, Mark Thompson (mot20@cam.ac.uk / mark@wildfiregames.com) // 2004-05-19 Mark Thompson (mot20@cam.ac.uk / mark@wildfiregames.com)
// 2004-06-18 janwas: replaced conversion buffer with stringstream // 2004-06-18 janwas: replaced conversion buffer with stringstream
// 2004-10-31 Philip: Changed to inherit from std::[w]string // 2004-10-31 Philip: Changed to inherit from std::[w]string
// 2007-1-26 greybeard(joe@wildfiregames.com): added comments for doc generation // 2007-01-26 greybeard(joe@wildfiregames.com): added comments for doc generation
#ifndef CSTR_H_FIRST #ifndef CSTR_H_FIRST
#define CSTR_H_FIRST #define CSTR_H_FIRST
@ -104,20 +104,19 @@ public:
* @param const tchar * String pointer to first tchar to be used for initialization * @param const tchar * String pointer to first tchar to be used for initialization
* @param size_t Length number of tchar to be used from first tchar * @param size_t Length number of tchar to be used from first tchar
**/ **/
CStr(const tchar* String, size_t Length) CStr(const tchar* String, size_t Length) : std::tstring(String, Length) {}
: std::tstring(String, Length) {}
/** /**
* Alternate Constructor * Alternate Constructor
* *
* @param const tchar Char tchar to be used for initialization * @param const tchar Char tchar to be used for initialization
**/ **/
CStr(const tchar Char) : std::tstring(1, Char) {} // std::string's constructor is (repeats, chr) CStr(tchar Char) : std::tstring(1, Char) {} // std::string's constructor is (repeats, chr)
/** /**
* Alternate Constructor * Alternate Constructor
* *
* @param std::tstring String reference to basic string object to be used for inititalization * @param std::tstring String reference to basic string object to be used for inititalization
**/ **/
CStr(std::tstring String) : std::tstring(String) {} CStr(const std::tstring& String) : std::tstring(String) {}
/** /**
* Repeat: Named constructor, to avoid overload overload. * Repeat: Named constructor, to avoid overload overload.
@ -135,7 +134,7 @@ public:
* *
* @param utf16string String utf16string to be used for initialization. * @param utf16string String utf16string to be used for initialization.
**/ **/
CStr(utf16string String) : std::tstring(String.begin(), String.end()) {} CStr(const utf16string& String) : std::tstring(String.begin(), String.end()) {}
// Transparent CStrW/8 conversion. Non-ASCII characters are not // Transparent CStrW/8 conversion. Non-ASCII characters are not
// handled correctly. // handled correctly.
@ -199,7 +198,8 @@ public:
**/ **/
~CStr() {}; ~CStr() {};
// Conversions // Conversions:
/** /**
* Return CStr as Integer. * Return CStr as Integer.
* Conversion is from the beginning of CStr. * Conversion is from the beginning of CStr.
@ -243,22 +243,6 @@ public:
**/ **/
double ToDouble() const; double ToDouble() const;
/**
* Return the length of the CStr in characters.
*
* @return size_t character count
**/
size_t Length() const { return length(); }
/**
* Retrieve the substring within the CStr.
*
* @param size_t start starting character position in CStr
* @param size_t len number of characters to retrieve in CStr
* @return CStr substring
**/
CStr GetSubstring(size_t start, size_t len) const;
/** /**
* Search the CStr for another string. * Search the CStr for another string.
* The search is case-sensitive. * The search is case-sensitive.
@ -276,7 +260,7 @@ public:
* @return long offset into the CStr of the first occurrence of the search string * @return long offset into the CStr of the first occurrence of the search string
* -1 if the search string is not found * -1 if the search string is not found
**/ **/
long Find(const tchar &chr) const; long Find(const tchar chr) const;
/** /**
* Search the CStr for another string with starting offset. * Search the CStr for another string with starting offset.
* The search is case-sensitive. * The search is case-sensitive.
@ -286,7 +270,7 @@ public:
* @return long offset into the CStr of the first occurrence of the search string * @return long offset into the CStr of the first occurrence of the search string
* -1 if the search string is not found * -1 if the search string is not found
**/ **/
long Find(const int &start, const tchar &chr) const; long Find(const int start, const tchar chr) const;
/** /**
* Search the CStr for another string. * Search the CStr for another string.
@ -305,7 +289,7 @@ public:
* @return long offset into the CStr of the first occurrence of the search string * @return long offset into the CStr of the first occurrence of the search string
* -1 if the search string is not found * -1 if the search string is not found
**/ **/
long FindInsensitive(const tchar &chr) const; long FindInsensitive(const tchar chr) const;
/** /**
* Search the CStr for another string with starting offset. * Search the CStr for another string with starting offset.
* The search is case-insensitive. * The search is case-insensitive.
@ -315,7 +299,7 @@ public:
* @return long offset into the CStr of the first occurrence of the search string * @return long offset into the CStr of the first occurrence of the search string
* -1 if the search string is not found * -1 if the search string is not found
**/ **/
long FindInsensitive(const int &start, const tchar &chr) const; long FindInsensitive(const int start, const tchar chr) const;
/** /**
* Search the CStr for another string. * Search the CStr for another string.
@ -339,8 +323,6 @@ public:
* @return CStr converted copy of CStr. * @return CStr converted copy of CStr.
**/ **/
CStr UpperCase() const; CStr UpperCase() const;
CStr LCase() const;
CStr UCase() const;
/** /**
* Retrieve first n characters of the CStr. * Retrieve first n characters of the CStr.
@ -363,40 +345,44 @@ public:
* Return substring of the CStr after the last occurrence of the search string. * Return substring of the CStr after the last occurrence of the search string.
* *
* @param const CStr & Str reference to search string * @param const CStr & Str reference to search string
* @param size_t startPos character position to start searching from
* @return CStr substring remaining after match * @return CStr substring remaining after match
* the CStr if no match is found * the CStr if no match is found
**/ **/
CStr AfterLast(const CStr& Str) const; CStr AfterLast(const CStr& Str, size_t startPos = npos) const;
/** /**
* Retrieve substring of the CStr preceding last occurrence of a string. * Retrieve substring of the CStr preceding last occurrence of a string.
* Return substring of the CStr preceding the last occurrence of the search string. * Return substring of the CStr preceding the last occurrence of the search string.
* *
* @param const CStr & Str reference to search string * @param const CStr & Str reference to search string
* @param size_t startPos character position to start searching from
* @return CStr substring preceding before match * @return CStr substring preceding before match
* the CStr if no match is found * the CStr if no match is found
**/ **/
CStr BeforeLast(const CStr& Str) const; CStr BeforeLast(const CStr& Str, size_t startPos = npos) const;
/** /**
* Retrieve substring of the CStr after first occurrence of a string. * Retrieve substring of the CStr after first occurrence of a string.
* Return substring of the CStr after the first occurrence of the search string. * Return substring of the CStr after the first occurrence of the search string.
* *
* @param const CStr & Str reference to search string * @param const CStr & Str reference to search string
* @param size_t startPos character position to start searching from
* @return CStr substring remaining after match * @return CStr substring remaining after match
* the CStr if no match is found * the CStr if no match is found
**/ **/
CStr AfterFirst(const CStr& Str) const; CStr AfterFirst(const CStr& Str, size_t startPos = 0) const;
/** /**
* Retrieve substring of the CStr preceding first occurrence of a string. * Retrieve substring of the CStr preceding first occurrence of a string.
* Return substring of the CStr preceding the first occurrence of the search string. * Return substring of the CStr preceding the first occurrence of the search string.
* *
* @param const CStr & Str reference to search string * @param const CStr & Str reference to search string
* @param size_t startPos character position to start searching from
* @return CStr substring preceding before match * @return CStr substring preceding before match
* the CStr if no match is found * the CStr if no match is found
**/ **/
CStr BeforeFirst(const CStr& Str) const; CStr BeforeFirst(const CStr& Str, size_t startPos = 0) const;
/** /**
* Remove all occurrences of a string from the CStr. * Remove all occurrences of a string from the CStr.
@ -418,7 +404,7 @@ public:
* *
* @return CStr converted copy of CStr. * @return CStr converted copy of CStr.
**/ **/
CStr UnescapeBackslashes(); CStr UnescapeBackslashes() const;
/** /**
* Return a trimmed copy of the CStr. * Return a trimmed copy of the CStr.
@ -492,13 +478,11 @@ public:
operator const tchar*() const; operator const tchar*() const;
// Do some range checking in debug builds tchar& operator[](size_t n) { return this->std::tstring::operator[](n); }
tchar& operator[](size_t n) { debug_assert(n < length()); return this->std::tstring::operator[](n); } tchar& operator[](int n) { return this->std::tstring::operator[](n); }
tchar& operator[](int n) { debug_assert((size_t)n < length()); return this->std::tstring::operator[](n); }
// Conversion to utf16string // Conversion to utf16string
inline utf16string utf16() const utf16string utf16() const { return utf16string(begin(), end()); }
{ return utf16string(begin(), end()); }
// Calculates a hash of the string's contents // Calculates a hash of the string's contents
size_t GetHashCode() const; size_t GetHashCode() const;

View File

@ -54,7 +54,7 @@ void CFilePacker::PackRaw(const void* rawdata,u32 rawdatalen)
// PackString: pack a string onto the end of the data stream // PackString: pack a string onto the end of the data stream
void CFilePacker::PackString(const CStr& str) void CFilePacker::PackString(const CStr& str)
{ {
u32 len=(u32)str.Length(); u32 len=(u32)str.length();
PackRaw(&len,sizeof(len)); PackRaw(&len,sizeof(len));
PackRaw((const char*) str,len); PackRaw((const char*) str,len);
} }

View File

@ -949,7 +949,7 @@ void Init(const CmdLineArgs& args, uint flags)
CONFIG_Init(args); CONFIG_Init(args);
// setup_gui must be set after CONFIG_Init, so command-line parameters can disable it // setup_gui must be set after CONFIG_Init, so command-line parameters can disable it
const bool setup_gui = ((flags & INIT_NO_GUI) == 0 && g_AutostartMap.Length() == 0); const bool setup_gui = ((flags & INIT_NO_GUI) == 0 && g_AutostartMap.empty());
// GUI is notified in SetVideoMode, so this must come before that. // GUI is notified in SetVideoMode, so this must come before that.
#ifndef NO_GUI #ifndef NO_GUI
@ -1102,7 +1102,7 @@ void Init(const CmdLineArgs& args, uint flags)
camera.UpdateFrustum(); camera.UpdateFrustum();
} }
if (g_AutostartMap.Length()) if (! g_AutostartMap.empty())
{ {
// Code copied mostly from atlas/GameInterface/Handlers/Map.cpp - // Code copied mostly from atlas/GameInterface/Handlers/Map.cpp -
// maybe should be refactored to avoid duplication // maybe should be refactored to avoid duplication

View File

@ -67,7 +67,7 @@ void CWorld::Initialize(CGameAttributes *pAttribs)
ONCE(RegMemFun(CEntityTemplateCollection::GetSingletonPtr(), &CEntityTemplateCollection::loadTemplates, L"loadTemplates", 15)); ONCE(RegMemFun(CEntityTemplateCollection::GetSingletonPtr(), &CEntityTemplateCollection::loadTemplates, L"loadTemplates", 15));
// Load the map, if one was specified // Load the map, if one was specified
if (pAttribs->m_MapFile.Length()) if (pAttribs->m_MapFile.length())
{ {
CStr mapfilename("maps/scenarios/"); CStr mapfilename("maps/scenarios/");

View File

@ -67,7 +67,7 @@ bool XMLWriter_File::StoreVFS(Handle h)
if (m_LastElement) debug_warn("ERROR: Saving XML while an element is still open"); if (m_LastElement) debug_warn("ERROR: Saving XML while an element is still open");
FileIOBuf data = (FileIOBuf)m_Data.data(); FileIOBuf data = (FileIOBuf)m_Data.data();
int err = vfs_io(h, m_Data.Length(), &data); int err = vfs_io(h, m_Data.length(), &data);
if (err < 0) if (err < 0)
{ {
LOG(ERROR, "xml", "Error saving XML data through VFS: %lld", h); LOG(ERROR, "xml", "Error saving XML data through VFS: %lld", h);

View File

@ -198,7 +198,7 @@ enum {
* Struct CRendererInternals: Truly hide data that is supposed to be hidden * Struct CRendererInternals: Truly hide data that is supposed to be hidden
* in this structure so it won't even appear in header files. * in this structure so it won't even appear in header files.
*/ */
struct CRendererInternals struct CRendererInternals : public boost::noncopyable
{ {
/// true if CRenderer::Open has been called /// true if CRenderer::Open has been called
bool IsOpen; bool IsOpen;

View File

@ -131,12 +131,12 @@ public:
if( Instance ) if( Instance )
{ {
size_t rlen = Instance->m_PropertyRoot.Length(); size_t rlen = Instance->m_PropertyRoot.length();
IJSComplex::PropertyTable::iterator iit; IJSComplex::PropertyTable::iterator iit;
for( iit = T::m_IntrinsicProperties.begin(); iit != T::m_IntrinsicProperties.end(); iit++ ) for( iit = T::m_IntrinsicProperties.begin(); iit != T::m_IntrinsicProperties.end(); iit++ )
if( ( iit->first.Length() > rlen ) && ( iit->first.Left( rlen ) == Instance->m_PropertyRoot ) && ( iit->first[rlen] == '.' ) ) if( ( iit->first.length() > rlen ) && ( iit->first.Left( rlen ) == Instance->m_PropertyRoot ) && ( iit->first[rlen] == '.' ) )
it->first.insert( iit->first.GetSubstring( rlen + 1, iit->first.Length() - rlen - 1 ).BeforeFirst( L"." ) ); it->first.insert( iit->first.BeforeFirst( L".", rlen + 1 ) );
Instance->m_Owner->FillEnumerateSet( it, &( Instance->m_PropertyRoot ) ); Instance->m_Owner->FillEnumerateSet( it, &( Instance->m_PropertyRoot ) );
@ -919,10 +919,10 @@ void CJSComplex<T, ReadOnly>::FillEnumerateSet( IteratorState* it, CStrW* Proper
PropertyTable::iterator iit; PropertyTable::iterator iit;
if( PropertyRoot ) if( PropertyRoot )
{ {
size_t rlen = PropertyRoot->Length(); size_t rlen = PropertyRoot->length();
for( iit = m_Properties.begin(); iit != m_Properties.end(); iit++ ) for( iit = m_Properties.begin(); iit != m_Properties.end(); iit++ )
if( ( iit->first.Length() > rlen ) && ( iit->first.Left( rlen ) == *PropertyRoot ) && ( iit->first[rlen] == '.' ) ) if( ( iit->first.length() > rlen ) && ( iit->first.Left( rlen ) == *PropertyRoot ) && ( iit->first[rlen] == '.' ) )
it->first.insert( iit->first.GetSubstring( rlen + 1, iit->first.Length() - rlen - 1 ).BeforeFirst( L"." ) ); it->first.insert( iit->first.BeforeFirst( L".", rlen + 1 ) );
} }
else else
{ {

View File

@ -137,16 +137,8 @@ jsval ScriptingHost::ExecuteScript(const CStrW& script, const CStrW& calledFrom,
{ {
jsval rval; jsval rval;
/* Unicode->ASCII conversion (mostly) for calledFrom */ JSBool ok = JS_EvaluateUCScript(m_Context, contextObject ? contextObject : m_GlobalObject,
script.utf16().c_str(), (int)script.length(), CStr(calledFrom), 1, &rval);
size_t len = wcstombs( NULL, calledFrom, 0 );
debug_assert( len != (size_t)-1 );
char* asciiName = new char[len + 1];
wcstombs( asciiName, calledFrom, len + 1 );
JSBool ok = JS_EvaluateUCScript(m_Context, contextObject ? contextObject : m_GlobalObject, script.utf16().c_str(), (int)script.Length(), asciiName, 1, &rval);
delete[]( asciiName );
if (!ok) return JSVAL_NULL; if (!ok) return JSVAL_NULL;

View File

@ -92,23 +92,23 @@ void CClassSet::setFromMemberList(const CStrW& list)
} }
else else
{ {
entry = temp.GetSubstring( 0, brk ); entry = temp.substr( 0, brk );
temp = temp.GetSubstring( brk + 1, temp.Length() ); temp = temp.substr( brk + 1 );
} }
if( brk != 0 ) if( brk != 0 )
{ {
if( entry[0] == '-' ) if( entry[0] == '-' )
{ {
entry = entry.GetSubstring( 1, entry.Length() ); entry = entry.substr( 1 );
if( entry.Length() ) if( ! entry.empty() )
m_RemovedMembers.push_back( entry ); m_RemovedMembers.push_back( entry );
} }
else else
{ {
if( entry[0] == '+' ) if( entry[0] == '+' )
entry = entry.GetSubstring( 1, entry.Length() ); entry = entry.substr( 1 );
if( entry.Length() ) if( ! entry.empty() )
m_AddedMembers.push_back( entry ); m_AddedMembers.push_back( entry );
} }
} }

View File

@ -181,7 +181,7 @@ bool CEntityTemplate::loadXML( const CStr& filename )
m_Base_Name = Root.getAttributes().getNamedItem( at_Parent ); m_Base_Name = Root.getAttributes().getNamedItem( at_Parent );
// Load our parent, if we have one // Load our parent, if we have one
if( m_Base_Name.Length() ) if( ! m_Base_Name.empty() )
{ {
CEntityTemplate* base = g_EntityTemplateCollection.getTemplate( m_Base_Name, m_player ); CEntityTemplate* base = g_EntityTemplateCollection.getTemplate( m_Base_Name, m_player );
if( base ) if( base )
@ -206,16 +206,16 @@ bool CEntityTemplate::loadXML( const CStr& filename )
{ {
CStr Include = Child.getAttributes().getNamedItem( at_File ); CStr Include = Child.getAttributes().getNamedItem( at_File );
if( Include.Length() && scriptsLoaded.find( Include ) == scriptsLoaded.end() ) if( !Include.empty() && scriptsLoaded.find( Include ) == scriptsLoaded.end() )
{ {
scriptsLoaded.insert( Include ); scriptsLoaded.insert( Include );
g_ScriptingHost.RunScript( Include ); g_ScriptingHost.RunScript( Include );
} }
CStr Inline = Child.getText(); CStr Inline = Child.getText();
if( Inline.Length() ) if( !Inline.empty() )
{ {
g_ScriptingHost.RunMemScript( Inline.c_str(), Inline.Length(), filename.c_str(), Child.getLineNumber() ); g_ScriptingHost.RunMemScript( Inline.c_str(), Inline.length(), filename.c_str(), Child.getLineNumber() );
} }
} }
else if (ChildName == el_Traits) else if (ChildName == el_Traits)

View File

@ -87,7 +87,7 @@ CEntityTemplate* CEntityTemplateCollection::getTemplate( const CStrW& name, CPla
void CEntityTemplateCollection::getEntityTemplateNames( std::vector<CStrW>& names ) void CEntityTemplateCollection::getEntityTemplateNames( std::vector<CStrW>& names )
{ {
for( TemplateFilenameMap::iterator it = m_templateFilenames.begin(); it != m_templateFilenames.end(); ++it ) for( TemplateFilenameMap::iterator it = m_templateFilenames.begin(); it != m_templateFilenames.end(); ++it )
if( ! (it->first.Length() > 8 && it->first.Left(8) == L"template")) if( ! (it->first.length() > 8 && it->first.Left(8) == L"template"))
names.push_back( it->first ); names.push_back( it->first );
} }

View File

@ -67,7 +67,7 @@ CFormation* CFormationCollection::getTemplate( const CStrW& name )
void CFormationCollection::getFormationNames( std::vector<CStrW>& names ) void CFormationCollection::getFormationNames( std::vector<CStrW>& names )
{ {
for( templateFilenameMap::iterator it = m_templateFilenames.begin(); it != m_templateFilenames.end(); ++it ) for( templateFilenameMap::iterator it = m_templateFilenames.begin(); it != m_templateFilenames.end(); ++it )
if( ! (it->first.Length() > 8 && it->first.Left(8) == L"template")) if( ! (it->first.length() > 8 && it->first.Left(8) == L"template"))
names.push_back( it->first ); names.push_back( it->first );
} }

View File

@ -268,15 +268,15 @@ bool CTechnology::loadELEffect( XMBElement effect, CXeromyces& XeroFile, const C
else if ( name == el_script ) else if ( name == el_script )
{ {
CStr Include = element.getAttributes().getNamedItem( at_file ); CStr Include = element.getAttributes().getNamedItem( at_file );
if( Include.Length() && m_scriptsLoaded.find( Include ) == m_scriptsLoaded.end() ) if( !Include.empty() && m_scriptsLoaded.find( Include ) == m_scriptsLoaded.end() )
{ {
m_scriptsLoaded.insert( Include ); m_scriptsLoaded.insert( Include );
g_ScriptingHost.RunScript( Include ); g_ScriptingHost.RunScript( Include );
} }
CStr Inline = element.getText(); CStr Inline = element.getText();
if( Inline.Length() ) if( !Inline.empty() )
{ {
g_ScriptingHost.RunMemScript( Inline.c_str(), Inline.Length(), filename, element.getLineNumber() ); g_ScriptingHost.RunMemScript( Inline.c_str(), Inline.length(), filename, element.getLineNumber() );
} }
} }
else if ( name == el_function ) else if ( name == el_function )