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 CGameView : private Scene
class CGameView : private Scene, public boost::noncopyable
{
public:
static const float defaultFOV, defaultNear, defaultFar;

View File

@ -70,7 +70,7 @@ void CMapReader::LoadMap(const char* filename, CTerrain *pTerrain_,
if (unpacker.GetVersion() >= 3) {
// read the corresponding XML file
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);
}

View File

@ -52,7 +52,7 @@ void CMapWriter::SaveMap(const char* filename, CTerrain* pTerrain,
packer.Write(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);
}

View File

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

View File

@ -222,9 +222,10 @@ CSkeletonAnim* CModel::BuildAnimation(const char* filename, const char* name, fl
// Update: update this model by the given time, in seconds
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
float animtime=time*m_AnimSpeed;
float animtime = time*m_AnimSpeed;
// update animation time, but don't calculate bone matrices - do that (lazily) when
// something requests them; that saves some calculation work for offscreen models,
@ -233,12 +234,13 @@ void CModel::Update(float time)
m_AnimTime += animtime;
float duration=m_Anim->m_AnimDef->GetDuration();
if (m_AnimTime > duration) {
float duration = m_Anim->m_AnimDef->GetDuration();
if (m_AnimTime > duration)
{
if (m_Flags & MODELFLAG_NOLOOPANIMATION)
SetAnimation(m_NextAnim);
else
m_AnimTime = (float) fmod(m_AnimTime, duration);
m_AnimTime = fmod(m_AnimTime, duration);
}
// mark vertices as dirty
@ -249,10 +251,8 @@ void CModel::Update(float time)
}
// 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);
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -462,8 +462,9 @@ void CModel::SetTransform(const CMatrix3D& transform)
void CModel::SetMaterial(const CMaterial &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]);
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;
else
chosenProps.erase(it->m_PropPointName);
@ -347,18 +347,18 @@ const CObjectBase::Variation CObjectBase::BuildVariation(const std::vector<u8>&
// Apply its data:
if (var.m_TextureFilename.Length())
if (! var.m_TextureFilename.empty())
variation.texture = var.m_TextureFilename;
if (var.m_ModelFilename.Length())
if (! var.m_ModelFilename.empty())
variation.model = var.m_ModelFilename;
if (var.m_Color.Length())
if (! var.m_Color.empty())
variation.color = var.m_Color;
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;
else
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]);
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;
else
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;
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);
if (prop)

View File

@ -49,7 +49,7 @@ bool CObjectEntry::BuildVariation(const std::vector<std::set<CStr> >& selections
m_TextureName = variation.texture;
m_ModelName = variation.model;
if (variation.color.Length())
if (! variation.color.empty())
{
std::stringstream str;
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 == "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);
if (anim)
@ -143,17 +143,17 @@ bool CObjectEntry::BuildVariation(const std::vector<std::set<CStr> >& selections
}
// Pluck out the special attachpoint 'projectile'
if( prop.m_PropPointName == "projectile" )
if (prop.m_PropPointName == "projectile")
{
m_ProjectileModel = oe->m_Model;
}
// 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_AmmunitionPoint = modeldef->FindPropPoint((const char*)ppn );
if( !m_AmmunitionPoint )
if (! m_AmmunitionPoint)
LOG(ERROR, LOG_CATEGORY, "Failed to find matching prop point called \"%s\" in model \"%s\" on actor \"%s\"", (const char*)ppn, (const char*)m_ModelName, (const char*)prop.m_ModelName);
}
else

View File

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

View File

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

View File

@ -50,7 +50,7 @@ void CButton::SetupText()
debug_assert(m_GeneratedTexts.size()>=1);
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
// TODO Gee: (2004-08-14) Default should not be hard-coded, but be in styles!
font = "default";

View File

@ -55,7 +55,7 @@ void CCheckBox::SetupText()
debug_assert(m_GeneratedTexts.size()>=1);
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
// TODO Gee: (2004-08-14) Default should not be hard-coded, but be in styles!
font = "default";

View File

@ -1243,7 +1243,7 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec
if (m_Styles.count("default") == 1)
object->LoadStyle(*this, "default");
if (argStyle.Length())
if (! argStyle.empty())
{
// additional check
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
if (hotkeyTag.Length())
if (! hotkeyTag.empty())
hotkeyRegisterGUIObject(object->GetName(), hotkeyTag);
CStrW caption (Element.getText());
if (caption.Length())
if (! caption.empty())
{
// Set the setting caption to this
object->SetSetting("caption", caption, true);
@ -1351,7 +1351,7 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec
CStr code;
// If there is a file, open it and use it as the code
if (file.Length())
if (! file.empty())
{
CVFSFile scriptfile;
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") ));
// If there is a file specified, open and execute it
if (file.Length())
if (! file.empty())
g_ScriptingHost.RunScript(file, m_ScriptObject);
// Execute inline scripts
CStr code (Element.getText());
if (code.Length())
g_ScriptingHost.RunMemScript(code.c_str(), code.Length(), "Some XML file", Element.getLineNumber(), m_ScriptObject);
if (! code.empty())
g_ScriptingHost.RunMemScript(code.c_str(), code.length(), "Some XML file", Element.getLineNumber(), m_ScriptObject);
}
void CGUI::Xeromyces_ReadSprite(XMBElement Element, CXeromyces* pFile)
@ -1878,7 +1878,7 @@ void CGUI::Xeromyces_ReadColor(XMBElement Element, CXeromyces* pFile)
// Try parsing value
CStr value (Element.getText());
if (value.Length())
if (! value.empty())
{
// Try setting color to value
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();
if (text)
{
if (m_iBufferPos == (int)pCaption->Length())
if (m_iBufferPos == (int)pCaption->length())
*pCaption += text;
else
*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);
@ -105,15 +105,15 @@ InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev)
{
m_iBufferPos_Tail = -1;
if (pCaption->Length() == 0 ||
if (pCaption->empty() ||
m_iBufferPos == 0)
break;
if (m_iBufferPos == (int)pCaption->Length())
*pCaption = pCaption->Left( (long) pCaption->Length()-1);
if (m_iBufferPos == (int)pCaption->length())
*pCaption = pCaption->Left( (long) pCaption->length()-1);
else
*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);
@ -132,12 +132,12 @@ InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev)
}
else
{
if (pCaption->Length() == 0 ||
m_iBufferPos == (int)pCaption->Length())
if (pCaption->empty() ||
m_iBufferPos == (int)pCaption->length())
break;
*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);
}
@ -177,7 +177,7 @@ InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev)
m_iBufferPos_Tail = m_iBufferPos;
}
m_iBufferPos = (long) pCaption->Length();
m_iBufferPos = (long) pCaption->length();
m_WantedX=0.f;
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;
}
else
@ -417,7 +417,7 @@ InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev)
// check max length
int 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;
m_WantedX=0.f;
@ -426,11 +426,11 @@ InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev)
DeleteCurSelection();
m_iBufferPos_Tail = -1;
if (m_iBufferPos == (int)pCaption->Length())
if (m_iBufferPos == (int)pCaption->length())
*pCaption += cooked;
else
*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);
@ -1029,7 +1029,7 @@ void CInput::UpdateText(int from, int to_before, int to_after)
int to = 0; // make sure it's initialized
if (to_before == -1)
to = (int)caption.Length();
to = (int)caption.length();
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())
to = destroy_row_to->m_ListStart; // notice it will iterate [from, to), so it will never reach to.
else
to = (int)caption.Length();
to = (int)caption.length();
// 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;
--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);
@ -1179,7 +1179,7 @@ void CInput::UpdateText(int from, int to_before, int to_after)
check_point_row_start += delta;
check_point_row_end += delta;
if (to != (int)caption.Length())
if (to != (int)caption.length())
to += delta;
}
}
@ -1195,10 +1195,10 @@ void CInput::UpdateText(int from, int to_before, int to_after)
{
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
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;
@ -1241,7 +1241,7 @@ void CInput::UpdateText(int from, int to_before, int to_after)
// both before and after that character, being on different
// rows. With automatic word-wrapping, that is not possible. Which
// 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;
@ -1348,7 +1348,7 @@ void CInput::UpdateText(int from, int to_before, int to_after)
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.
else
to = (int)caption.Length();
to = (int)caption.length();
// 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);
CStr c_caption(caption.GetSubstring(from, to-from));
CStr c_caption(caption.substr(from, to-from));
}
// else, the for loop will end naturally.
}
@ -1527,7 +1527,7 @@ void CInput::DeleteCurSelection()
}
*pCaption = pCaption->Left( VirtualFrom ) +
pCaption->Right( (long) pCaption->Length()-(VirtualTo) );
pCaption->Right( (long) pCaption->length()-(VirtualTo) );
UpdateText(VirtualFrom, VirtualTo, VirtualFrom);

View File

@ -78,7 +78,7 @@ void CList::SetupText()
m_GeneratedTexts.clear();
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
// TODO Gee: (2004-08-14) Don't define standard like this. Do it with the default style.
font = "default";

View File

@ -55,7 +55,7 @@ void CText::SetupText()
debug_assert(m_GeneratedTexts.size()>=1);
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
// TODO Gee: (2004-08-14) Don't define standard like this. Do it with the default style.
font = "default";

View File

@ -48,7 +48,7 @@ void CTooltip::SetupText()
debug_assert(m_GeneratedTexts.size()==1);
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";
float buffer_zone = 0.f;

View File

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

View File

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

View File

@ -180,7 +180,7 @@ void CGUIString::GenerateTextCall(SFeedback &Feedback,
TextCall.m_UseCustomColor = false;
// 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.
vector<CGUIString::TextChunk::Tag>::const_iterator it2;
@ -226,7 +226,7 @@ void CGUIString::GenerateTextCall(SFeedback &Feedback,
// These are also needed later
TextCall.m_Size = size;
if (TextCall.m_String.Length() >= 1)
if (! TextCall.m_String.empty())
{
if (TextCall.m_String[0] == '\n')
{
@ -320,12 +320,12 @@ void CGUIString::SetValue(const CStrW& str)
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_To = (int)m_RawString.Length();
CurrentTextChunk.m_To = (int)m_RawString.length();
m_TextChunks.push_back(CurrentTextChunk);
}
@ -340,23 +340,23 @@ void CGUIString::SetValue(const CStrW& str)
if (pos_right == -1)
{
m_RawString += str.GetSubstring(position, curpos-position+1);
m_RawString += str.substr(position, curpos-position+1);
continue;
}
else
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;
}
else
{
m_RawString += str.GetSubstring(position, curpos-position);
m_RawString += str.substr(position, curpos-position);
// Okay we've found a TagStart and TagEnd, positioned
// at pos and pos_right. Now let's extract the
// 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;
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
// 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;
@ -508,7 +508,7 @@ void CGUIString::SetValue(const CStrW& str)
// those cases.
// We'll sort later.
m_Words.push_back(0);
m_Words.push_back((int)m_RawString.Length());
m_Words.push_back((int)m_RawString.length());
// Space: ' '
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
// notice we won't add it if it's doesn't have any parent
// (i.e. being the base object)
if (m_Name.Length() == 0)
if (m_Name.empty())
{
throw PS_NEEDS_NAME;
}
@ -428,7 +428,8 @@ void IGUIObject::RegisterScriptHandler(const CStr& Action, const CStr& Code, CGU
char buf[64];
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
if (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
// an internal name
if (m_Name.Length() <= 12)
if (m_Name.length() <= 12)
return m_Name;
if (m_Name.GetSubstring(0, 10) == "__internal")
if (m_Name.substr(0, 10) == "__internal")
return CStr("[unnamed object]");
else
return m_Name;

View File

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

View File

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

View File

@ -319,9 +319,9 @@ CStr _nm::GetStringRaw() const \
#define NMT_END_ARRAY() \
++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) \
ret += #_nm _T(": "); \
@ -334,7 +334,7 @@ CStr _nm::GetStringRaw() const \
ret += _T(", ");
#define END_NMT_CLASS() \
return ret.GetSubstring(0, ret.Length()-2); \
return ret.substr(0, ret.length()-2); \
}
#include "NMTCreator.h"

View File

@ -700,29 +700,29 @@ void CConsole::LoadHistory()
// just don't load anything in that case.
// do this before vfs_load to avoid an error message if file not found.
if(!vfs_exists(m_sHistoryFile))
if (!vfs_exists(m_sHistoryFile))
return;
FileIOBuf buf; size_t buflen;
if(vfs_load( m_sHistoryFile, buf, buflen ) < 0)
if (vfs_load(m_sHistoryFile, buf, buflen) < 0)
return;
CStr bytes( (char*)buf, buflen );
CStr bytes ((char*)buf, buflen);
(void)file_buf_free(buf);
CStrW str( bytes.FromUTF8() );
CStrW str (bytes.FromUTF8());
size_t pos = 0;
while( pos != CStrW::npos )
while (pos != CStrW::npos)
{
pos = str.find( '\n' );
if( pos != CStrW::npos )
pos = str.find('\n');
if (pos != CStrW::npos)
{
if( pos > 0 )
m_deqBufHistory.push_front( str.Left( str[pos-1] == '\r' ? pos - 1 : pos ) );
str = str.GetSubstring( pos + 1, str.npos );
if (pos > 0)
m_deqBufHistory.push_front(str.Left(str[pos-1] == '\r' ? pos - 1 : pos));
str = str.substr(pos + 1);
}
else if( str.Length() > 0 )
m_deqBufHistory.push_front( str );
else if (str.length() > 0)
m_deqBufHistory.push_front(str);
}
}
@ -731,13 +731,13 @@ void CConsole::SaveHistory()
CStr buffer;
std::deque<std::wstring>::iterator it;
int line_count = 0;
for( it = m_deqBufHistory.begin(); it != m_deqBufHistory.end(); ++it )
for (it = m_deqBufHistory.begin(); it != m_deqBufHistory.end(); ++it)
{
if(line_count++ >= m_MaxHistoryLines)
if (line_count++ >= m_MaxHistoryLines)
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)

View File

@ -195,7 +195,7 @@ CStrW CStr8::FromUTF8() const
CStr CStr::Repeat(const CStr& String, size_t Reps)
{
CStr ret;
ret.reserve(String.Length() * Reps);
ret.reserve(String.length() * Reps);
while (Reps--) ret += String;
return ret;
}
@ -259,12 +259,6 @@ double CStr::ToDouble() const
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
long CStr::Find(const CStr& Str) const
@ -278,7 +272,7 @@ long CStr::Find(const CStr& Str) const
}
// 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);
@ -289,7 +283,7 @@ long CStr::Find(const tchar &chr) const
}
// 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);
@ -299,9 +293,9 @@ long CStr::Find(const int &start, const tchar &chr) const
return -1;
}
long CStr::FindInsensitive(const int &start, const tchar &chr) const { return LCase().Find(start, _totlower(chr)); }
long CStr::FindInsensitive(const tchar &chr) const { return LCase().Find(_totlower(chr)); }
long CStr::FindInsensitive(const CStr& Str) const { return LCase().Find(Str.LCase()); }
long CStr::FindInsensitive(const int start, const tchar chr) const { return LowerCase().Find(start, _totlower(chr)); }
long CStr::FindInsensitive(const tchar chr) const { return LowerCase().Find(_totlower(chr)); }
long CStr::FindInsensitive(const CStr& Str) const { return LowerCase().Find(Str.LowerCase()); }
long CStr::ReverseFind(const CStr& Str) const
@ -334,25 +328,6 @@ CStr CStr::UpperCase() const
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
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
// (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);
if (pos == -1)
size_t pos = rfind(Str, startPos);
if (pos == npos)
return *this;
else
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
// (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);
if (pos == -1)
size_t pos = rfind(Str, startPos);
if (pos == npos)
return *this;
else
return substr(0, pos);
@ -392,10 +367,10 @@ CStr CStr::BeforeLast(const CStr& Str) const
// Retrieve the substring following the first occurrence of 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);
if (pos == -1)
size_t pos = find(Str, startPos);
if (pos == npos)
return *this;
else
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
// (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);
if (pos == -1)
size_t pos = find(Str, startPos);
if (pos == npos)
return *this;
else
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
CStr NewString;
@ -587,17 +562,17 @@ size_t CStr::GetHashCode() const
CStrW is always serialized to/from UTF-16
*/
u8 *CStrW::Serialize(u8 *buffer) const
u8* CStrW::Serialize(u8* buffer) const
{
size_t len = length();
size_t i = 0;
for (i = 0; i < len; i++)
*(u16 *)(buffer + i*2) = htons((*this)[i]); // convert to network order (big-endian)
*(u16 *)(buffer+i*2) = 0;
return buffer+len*2+2;
*(u16 *)(buffer + i*2) = 0;
return buffer + len*2 + 2;
}
const u8 *CStrW::Deserialize(const u8 *buffer, const u8 *bufferend)
const u8* CStrW::Deserialize(const u8* buffer, const u8* bufferend)
{
const u16 *strend = (const u16 *)buffer;
while ((const u8 *)strend < bufferend && *strend) strend++;
@ -624,7 +599,7 @@ uint CStr::GetSerializedLength() const
in the CStr)
*/
u8 *CStr8::Serialize(u8 *buffer) const
u8* CStr8::Serialize(u8* buffer) const
{
size_t len = length();
size_t i = 0;
@ -634,7 +609,7 @@ u8 *CStr8::Serialize(u8 *buffer) const
return buffer+len+1;
}
const u8 *CStr8::Deserialize(const u8 *buffer, const u8 *bufferend)
const u8* CStr8::Deserialize(const u8* buffer, const u8* bufferend)
{
const u8 *strend = buffer;
while (strend < bufferend && *strend) strend++;

View File

@ -24,10 +24,10 @@ Examples:
*/
// 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-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
#define CSTR_H_FIRST
@ -81,43 +81,42 @@ public:
// CONSTRUCTORS
/**
* Constructor
*
**/
/**
* Constructor
*
**/
CStr() {}
/**
* Alternate Constructor
*
* @param const CStr & String reference to another CStr object to be used for initialization
**/
CStr(const CStr& String) : std::tstring(String) {}
/**
* Alternate Constructor
*
* @param const tchar * String pointer to an array of tchar to be used for initialization
**/
CStr(const tchar* String) : std::tstring(String) {}
/**
* Alternate Constructor
*
* @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
**/
CStr(const tchar* String, size_t Length)
: std::tstring(String, Length) {}
/**
* Alternate Constructor
*
* @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)
/**
* Alternate Constructor
*
* @param std::tstring String reference to basic string object to be used for inititalization
**/
CStr(std::tstring String) : std::tstring(String) {}
/**
* Alternate Constructor
*
* @param const CStr & String reference to another CStr object to be used for initialization
**/
CStr(const CStr& String) : std::tstring(String) {}
/**
* Alternate Constructor
*
* @param const tchar * String pointer to an array of tchar to be used for initialization
**/
CStr(const tchar* String) : std::tstring(String) {}
/**
* Alternate Constructor
*
* @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
**/
CStr(const tchar* String, size_t Length) : std::tstring(String, Length) {}
/**
* Alternate Constructor
*
* @param const tchar Char tchar to be used for initialization
**/
CStr(tchar Char) : std::tstring(1, Char) {} // std::string's constructor is (repeats, chr)
/**
* Alternate Constructor
*
* @param std::tstring String reference to basic string object to be used for inititalization
**/
CStr(const std::tstring& String) : std::tstring(String) {}
/**
* Repeat: Named constructor, to avoid overload overload.
@ -128,21 +127,21 @@ public:
**/
static CStr Repeat(const CStr& String, size_t Reps);
/**
* Construction from utf16strings.
* allowed on MSVC as of 2006-02-03 because utf16string is
* now distinct from CStrW.
*
* @param utf16string String utf16string to be used for initialization.
**/
CStr(utf16string String) : std::tstring(String.begin(), String.end()) {}
/**
* Construction from utf16strings.
* allowed on MSVC as of 2006-02-03 because utf16string is
* now distinct from CStrW.
*
* @param utf16string String utf16string to be used for initialization.
**/
CStr(const utf16string& String) : std::tstring(String.begin(), String.end()) {}
// Transparent CStrW/8 conversion. Non-ASCII characters are not
// handled correctly.
#ifndef _UNICODE
CStr8(const CStrW& wideStr);
#else
CStrW(const CStr8 &asciiStr);
CStrW(const CStr8& asciiStr);
#endif
// Conversion to/from UTF-8, encoded in a CStr8.
@ -156,108 +155,93 @@ public:
CStrW FromUTF8() const;
#endif
/**
* Alternate Constructor
*
* @param int Number integer to be used for initialization
**/
/**
* Alternate Constructor
*
* @param int Number integer to be used for initialization
**/
CStr(int Number);
/**
* Alternate Constructor
*
* @param unsigned int Number unsigned integer to be used for initialization
**/
/**
* Alternate Constructor
*
* @param unsigned int Number unsigned integer to be used for initialization
**/
CStr(unsigned int Number);
/**
* Alternate Constructor
*
* @param long Number long to be used for initialization
**/
/**
* Alternate Constructor
*
* @param long Number long to be used for initialization
**/
CStr(long Number);
/**
* Alternate Constructor
*
* @param unsigned long Number unsigned long to be used for initialization
**/
/**
* Alternate Constructor
*
* @param unsigned long Number unsigned long to be used for initialization
**/
CStr(unsigned long Number);
/**
* Alternate Constructor
*
* @param float Number float to be used for initialization
**/
/**
* Alternate Constructor
*
* @param float Number float to be used for initialization
**/
CStr(float Number);
/**
* Alternate Constructor
*
* @param double Number double to be used for initialization
**/
/**
* Alternate Constructor
*
* @param double Number double to be used for initialization
**/
CStr(double Number);
/**
* Destructor
*
**/
/**
* Destructor
*
**/
~CStr() {};
// Conversions
// Conversions:
/**
* Return CStr as Integer.
* Conversion is from the beginning of CStr.
*
* @return int CStr represented as an integer.
**/
int ToInt() const;
int ToInt() const;
/**
* Return CStr as Unsigned Integer.
* Conversion is from the beginning of CStr.
*
* @return unsigned int CStr represented as an unsigned integer.
**/
unsigned int ToUInt() const;
unsigned int ToUInt() const;
/**
* Return CStr as Long.
* Conversion is from the beginning of CStr.
*
* @return long CStr represented as a long.
**/
long ToLong() const;
long ToLong() const;
/**
* Return CStr as Unsigned Long.
* Conversion is from the beginning of CStr.
*
* @return unsigned long CStr represented as an unsigned long.
**/
unsigned long ToULong() const;
unsigned long ToULong() const;
/**
* Return CStr as Float.
* Conversion is from the beginning of CStr.
*
* @return float CStr represented as a float.
**/
float ToFloat() const;
float ToFloat() const;
/**
* Return CStr as Double.
* Conversion is from the beginning of CStr.
*
* @return double CStr represented as a double.
**/
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;
double ToDouble() const;
/**
* Search the CStr for another string.
@ -276,7 +260,7 @@ public:
* @return long offset into the CStr of the first occurrence of the search string
* -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.
* The search is case-sensitive.
@ -286,7 +270,7 @@ public:
* @return long offset into the CStr of the first occurrence of the search string
* -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.
@ -305,7 +289,7 @@ public:
* @return long offset into the CStr of the first occurrence of the search string
* -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.
* The search is case-insensitive.
@ -315,7 +299,7 @@ public:
* @return long offset into the CStr of the first occurrence of the search string
* -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.
@ -339,8 +323,6 @@ public:
* @return CStr converted copy of CStr.
**/
CStr UpperCase() const;
CStr LCase() const;
CStr UCase() const;
/**
* 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.
*
* @param const CStr & Str reference to search string
* @param size_t startPos character position to start searching from
* @return CStr substring remaining after match
* 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.
* Return substring of the CStr preceding the last occurrence of the 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
* 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.
* Return substring of the CStr after the first occurrence of the 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
* 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.
* Return substring of the CStr preceding the first occurrence of the 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
* 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.
@ -418,7 +404,7 @@ public:
*
* @return CStr converted copy of CStr.
**/
CStr UnescapeBackslashes();
CStr UnescapeBackslashes() const;
/**
* Return a trimmed copy of the CStr.
@ -492,13 +478,11 @@ public:
operator const tchar*() const;
// Do some range checking in debug builds
tchar& operator[](size_t n) { debug_assert(n < length()); return this->std::tstring::operator[](n); }
tchar& operator[](int n) { debug_assert((size_t)n < length()); return this->std::tstring::operator[](n); }
tchar& operator[](size_t n) { return this->std::tstring::operator[](n); }
tchar& operator[](int n) { return this->std::tstring::operator[](n); }
// Conversion to utf16string
inline utf16string utf16() const
{ return utf16string(begin(), end()); }
utf16string utf16() const { return utf16string(begin(), end()); }
// Calculates a hash of the string's contents
size_t GetHashCode() const;
@ -507,8 +491,8 @@ public:
// (These are not virtual or inherited from ISerializable, to avoid
// adding a vtable and making the strings larger than std::string)
uint GetSerializedLength() const;
u8 *Serialize(u8 *buffer) const;
const u8 *Deserialize(const u8 *buffer, const u8 *bufferend);
u8* Serialize(u8* buffer) const;
const u8* Deserialize(const u8* buffer, const u8* bufferend);
};
// Hash function (for STL_HASH_MAP, etc)

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
void CFilePacker::PackString(const CStr& str)
{
u32 len=(u32)str.Length();
u32 len=(u32)str.length();
PackRaw(&len,sizeof(len));
PackRaw((const char*) str,len);
}

View File

@ -949,7 +949,7 @@ void Init(const CmdLineArgs& args, uint flags)
CONFIG_Init(args);
// 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.
#ifndef NO_GUI
@ -1102,7 +1102,7 @@ void Init(const CmdLineArgs& args, uint flags)
camera.UpdateFrustum();
}
if (g_AutostartMap.Length())
if (! g_AutostartMap.empty())
{
// Code copied mostly from atlas/GameInterface/Handlers/Map.cpp -
// 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));
// Load the map, if one was specified
if (pAttribs->m_MapFile.Length())
if (pAttribs->m_MapFile.length())
{
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");
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)
{
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
* 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
bool IsOpen;

View File

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

View File

@ -137,16 +137,8 @@ jsval ScriptingHost::ExecuteScript(const CStrW& script, const CStrW& calledFrom,
{
jsval rval;
/* Unicode->ASCII conversion (mostly) for calledFrom */
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 );
JSBool ok = JS_EvaluateUCScript(m_Context, contextObject ? contextObject : m_GlobalObject,
script.utf16().c_str(), (int)script.length(), CStr(calledFrom), 1, &rval);
if (!ok) return JSVAL_NULL;

View File

@ -92,23 +92,23 @@ void CClassSet::setFromMemberList(const CStrW& list)
}
else
{
entry = temp.GetSubstring( 0, brk );
temp = temp.GetSubstring( brk + 1, temp.Length() );
entry = temp.substr( 0, brk );
temp = temp.substr( brk + 1 );
}
if( brk != 0 )
{
if( entry[0] == '-' )
{
entry = entry.GetSubstring( 1, entry.Length() );
if( entry.Length() )
entry = entry.substr( 1 );
if( ! entry.empty() )
m_RemovedMembers.push_back( entry );
}
else
{
if( entry[0] == '+' )
entry = entry.GetSubstring( 1, entry.Length() );
if( entry.Length() )
entry = entry.substr( 1 );
if( ! entry.empty() )
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 );
// 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 );
if( base )
@ -206,16 +206,16 @@ bool CEntityTemplate::loadXML( const CStr& filename )
{
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 );
g_ScriptingHost.RunScript( Include );
}
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)

View File

@ -87,7 +87,7 @@ CEntityTemplate* CEntityTemplateCollection::getTemplate( const CStrW& name, CPla
void CEntityTemplateCollection::getEntityTemplateNames( std::vector<CStrW>& names )
{
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 );
}

View File

@ -67,7 +67,7 @@ CFormation* CFormationCollection::getTemplate( const CStrW& name )
void CFormationCollection::getFormationNames( std::vector<CStrW>& names )
{
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 );
}

View File

@ -268,15 +268,15 @@ bool CTechnology::loadELEffect( XMBElement effect, CXeromyces& XeroFile, const C
else if ( name == el_script )
{
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 );
g_ScriptingHost.RunScript( Include );
}
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 )