OpenClonk
Standard.h File Reference
#include <type_traits>
Include dependency graph for Standard.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define sprintf   ssprintf
 

Functions

template<class T >
std::enable_if< std::is_nothrow_default_constructible< T >::value >::type InplaceReconstruct (T *obj)
 
template<class T >
Abs (T val)
 
template<class T , class U , class V >
bool Inside (T ival, U lbound, V rbound)
 
template<class T >
Clamp (T bval, T lbound, T rbound)
 
template<class T >
int Sign (T val)
 
int DWordAligned (int val)
 
int32_t Distance (int32_t iX1, int32_t iY1, int32_t iX2, int32_t iY2)
 
int32_t Angle (int32_t iX1, int32_t iY1, int32_t iX2, int32_t iY2, int32_t iPrec=1)
 
int Pow (int base, int exponent)
 
int32_t StrToI32 (const char *s, int base, const char **scan_end)
 
template<class T >
std::enable_if< std::is_pod< T >::value >::type ZeroMem (T *lpMem, size_t dwSize)
 
void MemCopy (const void *lpMem1, void *lpMem2, size_t dwSize)
 
char CharCapital (char cChar)
 
bool IsIdentifier (char cChar)
 
bool IsWhiteSpace (char cChar)
 
size_t SLen (const char *sptr)
 
size_t SLenUntil (const char *szStr, char cUntil)
 
uint32_t GetNextUTF8Character (const char **pszString)
 
uint32_t GetNextCharacter (const char **pszString)
 
int GetCharacterCount (const char *s)
 
bool SEqual (const char *szStr1, const char *szStr2)
 
bool SEqual2 (const char *szStr1, const char *szStr2)
 
bool SEqualUntil (const char *szStr1, const char *szStr2, char cWild)
 
bool SEqualNoCase (const char *szStr1, const char *szStr2, int iLen=-1)
 
bool SEqual2NoCase (const char *szStr1, const char *szStr2, int iLen=-1)
 
void SCopy (const char *szSource, char *sTarget)
 
void SCopy (const char *szSource, char *sTarget, size_t iMaxL)
 
void SCopyUntil (const char *szSource, char *sTarget, char cUntil, int iMaxL=-1, int iIndex=0)
 
void SCopyUntil (const char *szSource, char *sTarget, const char *sUntil, size_t iMaxL)
 
void SCopyIdentifier (const char *szSource, char *sTarget, int iMaxL=0)
 
bool SCopySegment (const char *fstr, int segn, char *tstr, char sepa=';', int iMaxL=-1, bool fSkipWhitespace=false)
 
bool SCopySegmentEx (const char *fstr, int segn, char *tstr, char sepa1, char sepa2, int iMaxL=-1, bool fSkipWhitespace=false)
 
bool SCopyEnclosed (const char *szSource, char cOpen, char cClose, char *sTarget, int iSize)
 
void SAppend (const char *szSource, char *szTarget, int iMaxL=-1)
 
void SAppendChar (char cChar, char *szStr)
 
void SInsert (char *szString, const char *szInsert, int iPosition=0, int iMaxLen=-1)
 
void SDelete (char *szString, int iLen, int iPosition=0)
 
int SCharPos (char cTarget, const char *szInStr, int iIndex=0)
 
int SCharLastPos (char cTarget, const char *szInStr)
 
unsigned int SCharCount (char cTarget, const char *szInStr, const char *cpUntil=nullptr)
 
unsigned int SCharCountEx (const char *szString, const char *szCharList)
 
void SReplaceChar (char *str, char fc, char tc)
 
const char * SSearch (const char *szString, const char *szIndex)
 
const char * SSearchNoCase (const char *szString, const char *szIndex)
 
const char * SAdvanceSpace (const char *szSPos)
 
const char * SAdvancePast (const char *szSPos, char cPast)
 
bool SGetModule (const char *szList, int iIndex, char *sTarget, int iSize=-1)
 
bool SIsModule (const char *szList, const char *szString, int *ipIndex=nullptr, bool fCaseSensitive=false)
 
bool SAddModule (char *szList, const char *szModule, bool fCaseSensitive=false)
 
bool SAddModules (char *szList, const char *szModules, bool fCaseSensitive=false)
 
bool SRemoveModule (char *szList, const char *szModule, bool fCaseSensitive=false)
 
bool SRemoveModules (char *szList, const char *szModules, bool fCaseSensitive=false)
 
int SModuleCount (const char *szList)
 
void SNewSegment (char *szStr, const char *szSepa=";")
 
void SCapitalize (char *szString)
 
void SWordWrap (char *szText, char cSpace, char cSepa, int iMaxLine)
 
int SClearFrontBack (char *szString, char cClear=' ')
 
int SGetLine (const char *szText, const char *cpPosition)
 
int SLineGetCharacters (const char *szText, const char *cpPosition)
 
bool SWildcardMatchEx (const char *szString, const char *szWildcard)
 
int osprintf (char *str, const char *fmt,...) GNUC_FORMAT_ATTRIBUTE_O
 
template<size_t N>
int ssprintf (char(&str)[N], const char *fmt,...) GNUC_FORMAT_ATTRIBUTE_O
 
bool IsValidUtf8 (const char *string, int length=-1)
 
std::string vstrprintf (const char *format, va_list args)
 
std::string strprintf (const char *format,...) GNUC_FORMAT_ATTRIBUTE
 

Macro Definition Documentation

◆ sprintf

#define sprintf   ssprintf

Definition at line 162 of file Standard.h.

Function Documentation

◆ Abs()

◆ Angle()

int32_t Angle ( int32_t  iX1,
int32_t  iY1,
int32_t  iX2,
int32_t  iY2,
int32_t  iPrec = 1 
)

Definition at line 37 of file Standard.cpp.

38 {
39  int32_t iAngle;
40  int32_t dx = iX2 - iX1, dy = iY2 - iY1;
41  if (!dx)
42  {
43  if (dy > 0) return 180 * iPrec;
44  else return 0;
45  }
46  if (!dy)
47  {
48  if (dx > 0) return 90 * iPrec;
49  else return 270 * iPrec;
50  }
51 
52  iAngle = static_cast<int32_t>(180.0 * iPrec * atan2(static_cast<double>(Abs(dy)), static_cast<double>(Abs(dx))) / M_PI);
53 
54  if (iX2 > iX1)
55  {
56  if (iY2 < iY1) iAngle = (90 * iPrec) - iAngle;
57  else iAngle = (90 * iPrec) + iAngle;
58  }
59  else
60  {
61  if (iY2 < iY1) iAngle = (270 * iPrec) + iAngle;
62  else iAngle = (270 * iPrec) - iAngle;
63  }
64 
65  return iAngle;
66 }
T Abs(T val)
Definition: Standard.h:42

References Abs().

Referenced by C4FindObjectCone::Check(), C4Object::Draw(), C4ValueProviderCosV::Execute(), C4ValueProviderSinV::Execute(), C4Command::FlightControl(), InitCoreFunctionMap(), C4Command::JumpControl(), C4Command::MoveTo(), and C4BltTransform::Rotate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CharCapital()

char CharCapital ( char  cChar)
inline

Definition at line 70 of file Standard.h.

70 { return std::toupper(cChar); }

Referenced by SCapitalize(), SEqual2NoCase(), SEqualNoCase(), and SSearchNoCase().

Here is the caller graph for this function:

◆ Clamp()

◆ Distance()

int32_t Distance ( int32_t  iX1,
int32_t  iY1,
int32_t  iX2,
int32_t  iY2 
)

Definition at line 25 of file Standard.cpp.

26 {
27  int64_t dx = int64_t(iX1)-iX2, dy = int64_t(iY1)-iY2;
28  int64_t d2 = dx*dx+dy*dy;
29  if (d2 < 0) return -1;
30  int32_t dist = int32_t(sqrt(double(d2)));
31  if (int64_t(dist)*dist < d2) ++dist;
32  if (int64_t(dist)*dist > d2) --dist;
33  return dist;
34 }

Referenced by C4MapScriptAlgoLines::C4MapScriptAlgoLines(), C4PathFinderRay::Execute(), C4ValueProviderAbsX::Execute(), C4ValueProviderDist::Execute(), C4Command::FlightControl(), C4Command::Get(), C4ViewportList::GetAudibility(), InitCoreFunctionMap(), C4Command::JumpControl(), C4Command::MoveTo(), SumPathLength::operator()(), C4Command::Put(), C4Object::SetAudibilityAt(), and TrajectoryDistance().

Here is the caller graph for this function:

◆ DWordAligned()

int DWordAligned ( int  val)
inline

Definition at line 47 of file Standard.h.

48 {
49  if (val%4) { val>>=2; val<<=2; val+=4; }
50  return val;
51 }

Referenced by CSurface8::Read(), C4Surface::ReadBMP(), CSurface8::Save(), C4BMP256Info::Set(), and C4BMPInfo::Set().

Here is the caller graph for this function:

◆ GetCharacterCount()

int GetCharacterCount ( const char *  s)

Definition at line 791 of file Standard.cpp.

792 {
793  int l = 0;
794  while (*s)
795  {
796  unsigned char c = *s;
797  if (c < 128 || c > 247)
798  {
799  ++l;
800  s += 1;
801  }
802  else if (c > 191 && c < 224)
803  {
804  ++l;
805  s += 2;
806  }
807  else if (c >= 224 && c <= 239)
808  {
809  ++l;
810  s += 3;
811  }
812  else if (c >= 240 && c <= 247)
813  {
814  ++l;
815  s += 4;
816  }
817  else assert(false);
818  }
819  return l;
820 }
#define s

References s.

◆ GetNextCharacter()

uint32_t GetNextCharacter ( const char **  pszString)
inline

Definition at line 84 of file Standard.h.

85 {
86  unsigned char c=**pszString;
87  if (c<128) { ++*pszString; return c; }
88  else return GetNextUTF8Character(pszString);
89 }
uint32_t GetNextUTF8Character(const char **pszString)
Definition: Standard.cpp:755

References GetNextUTF8Character().

Referenced by CStdFont::BreakMessage(), C4MenuItem::DoTextProgress(), CStdFont::DrawText(), C4GUI::ExpandHotkeyMarkup(), and CStdFont::GetTextExtent().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetNextUTF8Character()

uint32_t GetNextUTF8Character ( const char **  pszString)

Definition at line 755 of file Standard.cpp.

756 {
757  // assume the current character is UTF8 already (i.e., highest bit set)
758  const uint32_t REPLACEMENT_CHARACTER = 0xFFFDu;
759  const char *szString = *pszString;
760  unsigned char c = *szString++;
761  uint32_t dwResult = REPLACEMENT_CHARACTER;
762  assert(c>127);
763  if (c>191 && c<224)
764  {
765  unsigned char c2 = *szString++;
766  if ((c2 & 192) != 128) { *pszString = szString; return REPLACEMENT_CHARACTER; }
767  dwResult = (int(c&31)<<6) | (c2&63); // two char code
768  }
769  else if (c >= 224 && c <= 239)
770  {
771  unsigned char c2 = *szString++;
772  if ((c2 & 192) != 128) { *pszString = szString; return REPLACEMENT_CHARACTER; }
773  unsigned char c3 = *szString++;
774  if ((c3 & 192) != 128) { *pszString = szString; return REPLACEMENT_CHARACTER; }
775  dwResult = (int(c&15)<<12) | (int(c2&63)<<6) | int(c3&63); // three char code
776  }
777  else if (c >= 240 && c <= 247)
778  {
779  unsigned char c2 = *szString++;
780  if ((c2 & 192) != 128) { *pszString = szString; return REPLACEMENT_CHARACTER; }
781  unsigned char c3 = *szString++;
782  if ((c3 & 192) != 128) { *pszString = szString; return REPLACEMENT_CHARACTER; }
783  unsigned char c4 = *szString++;
784  if ((c4 & 192) != 128) { *pszString = szString; return REPLACEMENT_CHARACTER; }
785  dwResult = (int(c&7)<<18) | (int(c2&63)<<12) | (int(c3&63)<<6) | int(c4&63); // four char code
786  }
787  *pszString = szString;
788  return dwResult;
789 }

Referenced by GetNextCharacter(), and ModXMLData::ModXMLData().

Here is the caller graph for this function:

◆ InplaceReconstruct()

template<class T >
std::enable_if<std::is_nothrow_default_constructible<T>::value>::type InplaceReconstruct ( T *  obj)
inline

Definition at line 35 of file Standard.h.

36 {
37  obj->~T();
38  new (obj) T();
39 }

Referenced by C4NameList::Clear(), C4BMPInfo::Default(), C4BMP256Info::Default(), C4RoundResult::Default(), C4Shape::Default(), and C4GroupEntry::Set().

Here is the caller graph for this function:

◆ Inside()

◆ IsIdentifier()

bool IsIdentifier ( char  cChar)

Definition at line 90 of file Standard.cpp.

91 {
92  if (Inside(cChar,'A','Z')) return true;
93  if (Inside(cChar,'a','z')) return true;
94  if (Inside(cChar,'0','9')) return true;
95  if (cChar=='_') return true;
96  if (cChar=='~') return true;
97  if (cChar=='+') return true;
98  if (cChar=='-') return true;
99  return false;
100 }
bool Inside(T ival, U lbound, V rbound)
Definition: Standard.h:43

References Inside().

Referenced by C4MaterialMap::LoadEnumeration(), C4LangStringTable::ReplaceStrings(), and SCopyIdentifier().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsValidUtf8()

bool IsValidUtf8 ( const char *  string,
int  length = -1 
)

Definition at line 702 of file Standard.cpp.

703 {
704  // Intentionally using a C-style cast to always get a uint8_t* from char*;
705  // reinterpret_cast would fail here on platforms that have unsigned char,
706  // while static_cast would fail on platforms with a signed char type
707  const uint8_t *input = (const uint8_t*)(text);
708 
709  for (const uint8_t *cursor = input; length < 0 ? *cursor != 0 : cursor - input < length; ++cursor)
710  {
711  int continuation_bytes = utf8_continuation_byte_table[*cursor];
712  if (continuation_bytes < 0)
713  return false;
714  else if (continuation_bytes == 0)
715  {
716  // Standard 7-bit ASCII value (i.e., 1 byte codepoint)
717  continue;
718  }
719  else if (length >= 0 && cursor - input + continuation_bytes >= length)
720  {
721  // Too few remaining bytes
722  return false;
723  }
724 
725  // Compute character value, so we can detect overlong sequences
726  assert((*cursor & 0xC0) == 0xC0);
727  uint32_t value = *cursor;
728  // strip length bits off the start byte
729  value &= (0xFF >> (continuation_bytes + 1));
730  for (int byte = 0; byte < continuation_bytes; ++byte)
731  {
732  // check that this is actually a continuation byte
733  if ((cursor[byte + 1] & 0xC0) != 0x80)
734  return false;
735  // merge continuation byte into value
736  value <<= 6;
737  value |= cursor[byte + 1] & 0x3F;
738  }
739  // make sure this is not overlong
740  if (value < utf8_min_char_value[continuation_bytes])
741  return false;
742  // and also not beyond 0x10FFFF
743  if (value > 0x10FFFF)
744  return false;
745  // and also not a wrongly encoded UTF-16 surrogate half
746  if (value >= 0xD800 && value <= 0xDFFF)
747  return false;
748  cursor += continuation_bytes;
749  }
750  // Looks fine
751  return true;
752 }

References C4ScriptGuiWindowPropertyName::text.

Referenced by CStdFont::DrawText(), StdStrBuf::EnsureUnicode(), CStdFont::GetTextExtent(), and ModXMLData::ModXMLData().

Here is the caller graph for this function:

◆ IsWhiteSpace()

bool IsWhiteSpace ( char  cChar)
inline

Definition at line 72 of file Standard.h.

72 { return !!std::isspace((unsigned char)cChar); }

Referenced by MakeFilenameFromTitle(), C4MessageInput::ProcessInput(), SAdvanceSpace(), and SRewindSpace().

Here is the caller graph for this function:

◆ MemCopy()

void MemCopy ( const void *  lpMem1,
void *  lpMem2,
size_t  dwSize 
)
inline

Definition at line 65 of file Standard.h.

66 {
67  std::memmove(lpMem2,lpMem1,dwSize);
68 }

Referenced by StdCompilerINIRead::Raw(), SDelete(), and SInsert().

Here is the caller graph for this function:

◆ osprintf()

int osprintf ( char *  str,
const char *  fmt,
  ... 
)
inline

Definition at line 155 of file Standard.h.

156 {
157  va_list args; va_start(args, fmt);
158  return vsprintf(str, fmt, args);
159 }

Referenced by MakeTempFilename().

Here is the caller graph for this function:

◆ Pow()

int Pow ( int  base,
int  exponent 
)

Definition at line 69 of file Standard.cpp.

70 {
71  if (exponent < 0) return 0;
72 
73  int result = 1;
74 
75  if (exponent & 1) result = base;
76  exponent >>= 1;
77 
78  while (exponent)
79  {
80  base *= base;
81  if (exponent & 1) result *= base;
82  exponent >>= 1;
83  }
84 
85  return result;
86 }

Referenced by C4AulCompiler::ConstexprEvaluator::visit().

Here is the caller graph for this function:

◆ SAddModule()

bool SAddModule ( char *  szList,
const char *  szModule,
bool  fCaseSensitive = false 
)

Definition at line 563 of file Standard.cpp.

564 {
565  // Safety / no empties
566  if (!szList || !szModule || !szModule[0]) return false;
567  // Already a module?
568  if (SIsModule(szList,szModule,nullptr,fCaseSensitive)) return false;
569  // New segment, add string
570  SNewSegment(szList);
571  SAppend(szModule,szList);
572  // Success
573  return true;
574 }
bool SIsModule(const char *szList, const char *szString, int *ipIndex, bool fCaseSensitive)
Definition: Standard.cpp:547
void SNewSegment(char *szStr, const char *szSepa)
Definition: Standard.cpp:474
void SAppend(const char *szSource, char *szTarget, int iMaxL)
Definition: Standard.cpp:263

References SAppend(), SIsModule(), and SNewSegment().

Referenced by C4Config::AddModule(), C4Console::FileOpenWPlrs(), C4Application::ParseCommandLine(), SAddModules(), and C4StartupMainDlg::UpdateParticipants().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SAddModules()

bool SAddModules ( char *  szList,
const char *  szModules,
bool  fCaseSensitive = false 
)

Definition at line 576 of file Standard.cpp.

577 {
578  // Safety / no empties
579  if (!szList || !szModules || !szModules[0]) return false;
580  // Add modules
581  char szModule[1024+1]; // limited
582  for (int cnt=0; SGetModule(szModules,cnt,szModule,1024); cnt++)
583  SAddModule(szList,szModule,fCaseSensitive);
584  // Success
585  return true;
586 }
bool SGetModule(const char *szList, int iIndex, char *sTarget, int iSize)
Definition: Standard.cpp:539
bool SAddModule(char *szList, const char *szModule, bool fCaseSensitive)
Definition: Standard.cpp:563

References SAddModule(), and SGetModule().

Referenced by C4StartupScenSelDlg::KeyCheat2().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SAdvancePast()

const char* SAdvancePast ( const char *  szSPos,
char  cPast 
)

Definition at line 438 of file Standard.cpp.

439 {
440  if (!szSPos) return nullptr;
441  while (*szSPos)
442  {
443  if (*szSPos==cPast) { szSPos++; break; }
444  szSPos++;
445  }
446  return szSPos;
447 }

Referenced by C4GameMessage::Append(), and C4Application::ParseCommandLine().

Here is the caller graph for this function:

◆ SAdvanceSpace()

const char* SAdvanceSpace ( const char *  szSPos)

Definition at line 420 of file Standard.cpp.

421 {
422  if (!szSPos) return nullptr;
423  while (IsWhiteSpace(*szSPos)) szSPos++;
424  return szSPos;
425 }
bool IsWhiteSpace(char cChar)
Definition: Standard.h:72

References IsWhiteSpace().

Referenced by C4MaterialMap::LoadEnumeration(), SCopySegment(), and SCopySegmentEx().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SAppend()

void SAppend ( const char *  szSource,
char *  szTarget,
int  iMaxL = -1 
)

Definition at line 263 of file Standard.cpp.

264 {
265  if (iMaxL == -1)
266  SCopy(szSource, szTarget + SLen(szTarget));
267  else
268  SCopy(szSource, szTarget + SLen(szTarget), iMaxL - SLen(szTarget));
269 }
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:152
size_t SLen(const char *sptr)
Definition: Standard.h:74

References SCopy(), and SLen().

Referenced by C4Group_CopyItem(), C4Group_MoveItem(), C4Group_PackDirectoryTo(), CopyDirectory(), DefaultExtension(), C4ConfigGeneral::DeterminePaths(), C4UpdatePackage::DoGrpUpdate(), EnforceExtension(), EraseDirectory(), C4Group::ExtractEntry(), C4Console::FileOpenWPlrs(), C4Network2ResList::FindTempResFileName(), ForEachFile(), C4ConfigGeneral::GetLanguageSequence(), C4ComponentHost::GetLanguageString(), C4Language::GetPackGroups(), C4Network2::Join(), C4DefGraphics::Load(), C4SoundEffect::Load(), C4UpdatePackage::MkUp(), RealPath(), C4Group::Rename(), C4ScenarioListLoader::Entry::RenameTo(), SAddModule(), C4Group::Save(), C4ObjectInfo::Save(), C4MaterialMap::SaveEnumeration(), C4Surface::SavePNG(), SetClientPrefix(), SNewSegment(), C4Playback::StreamToRecord(), and C4ObjectList::Write().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SAppendChar()

void SAppendChar ( char  cChar,
char *  szStr 
)

Definition at line 271 of file Standard.cpp.

272 {
273  if (!szStr) return;
274  char *cPos;
275  for (cPos=szStr; *cPos; cPos++) {}
276  *cPos=cChar; *(cPos+1)=0;
277 }

Referenced by AppendBackslash(), C4UpdatePackage::DoGrpUpdate(), C4ConfigGeneral::GetLanguageSequence(), C4Language::GetPackGroups(), and SetClientPrefix().

Here is the caller graph for this function:

◆ SCapitalize()

void SCapitalize ( char *  szString)

Definition at line 360 of file Standard.cpp.

361 {
362  while (str && *str)
363  {
364  *str=CharCapital(*str);
365  str++;
366  }
367 }
char CharCapital(char cChar)
Definition: Standard.h:70

References CharCapital().

Referenced by C4ChatInputDialog::OnChatInput().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SCharCount()

unsigned int SCharCount ( char  cTarget,
const char *  szInStr,
const char *  cpUntil = nullptr 
)

Definition at line 326 of file Standard.cpp.

327 {
328  unsigned int iResult=0;
329  // Scan string
330  while (*szInStr)
331  {
332  // End position reached (end character is not included)
333  if (szInStr==cpUntil) return iResult;
334  // Character found
335  if (*szInStr==cTarget) iResult++;
336  // Advance
337  szInStr++;
338  }
339  // Done
340  return iResult;
341 }
int iResult
Definition: C4GroupMain.cpp:40

References iResult.

Referenced by C4Group_IsExcluded(), C4ObjectInfoCore::Default(), C4Group::Delete(), C4Group::Extract(), C4MessageBoard::GetMessagePlayer(), GetParentPath(), IsSmallInputQuery(), IsWildcardString(), main(), C4Group::Merge(), C4Group::OpenAsChild(), C4Game::QuickSave(), SCharCountEx(), and SortRank().

Here is the caller graph for this function:

◆ SCharCountEx()

unsigned int SCharCountEx ( const char *  szString,
const char *  szCharList 
)

Definition at line 343 of file Standard.cpp.

344 {
345  unsigned int iResult = 0;
346  while ( *szCharList )
347  {
348  iResult += SCharCount( *szCharList, szString );
349  szCharList++;
350  }
351  return iResult;
352 }
unsigned int SCharCount(char cTarget, const char *szInStr, const char *cpUntil)
Definition: Standard.cpp:326

References iResult, and SCharCount().

Referenced by C4LeagueSignupDialog::UserClose().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SCharLastPos()

int SCharLastPos ( char  cTarget,
const char *  szInStr 
)

Definition at line 253 of file Standard.cpp.

254 {
255  const char *cpos;
256  int ccpos,lcpos;
257  if (!szInStr) return -1;
258  for (cpos=szInStr,ccpos=0,lcpos=-1; *cpos; cpos++,ccpos++)
259  if (*cpos==cTarget) lcpos=ccpos;
260  return lcpos;
261 }

Referenced by EraseDirectory(), C4Surface::Load(), C4DefGraphics::Load(), C4PlayerControlAssignment::ResolveRefs(), and TruncatePath().

Here is the caller graph for this function:

◆ SCharPos()

int SCharPos ( char  cTarget,
const char *  szInStr,
int  iIndex = 0 
)

Definition at line 239 of file Standard.cpp.

240 {
241  const char *cpos;
242  int ccpos;
243  if (!szInStr) return -1;
244  for (cpos=szInStr,ccpos=0; *cpos; cpos++,ccpos++)
245  if (*cpos==cTarget)
246  {
247  if (iIndex==0) return ccpos;
248  else iIndex--;
249  }
250  return -1;
251 }

Referenced by CStdFont::BreakMessage(), C4MenuItem::DoTextProgress(), CStdFont::DrawText(), FnParTexCol(), ForEachFile(), C4ComponentHost::GetLanguageString(), CStdFont::GetTextExtent(), C4AchievementGraphics::Init(), C4RankSystem::Load(), C4DefGraphics::Load(), C4GameResList::LoadFoldersWithLocalDefs(), C4Game::LoadScenarioComponents(), MakeFilenameFromTitle(), C4MainMenu::MenuCommand(), C4MessageInput::ProcessCommand(), C4Markup::Read(), SCopyEnclosed(), SCopySegment(), SCopySegmentEx(), and SRemoveModule().

Here is the caller graph for this function:

◆ SClearFrontBack()

int SClearFrontBack ( char *  szString,
char  cClear = ' ' 
)

Definition at line 461 of file Standard.cpp.

462 {
463  int cleared=0;
464  char *cpos;
465  if (!szString) return 0;
466  for (cpos=szString; *cpos && (*cpos==cClear); cpos++,cleared++) {}
467  // strcpy is undefined when used on overlapping strings...
468  if (cpos!=szString) memmove(szString, cpos, SLen(cpos) + 1);
469  for (cpos=szString+SLen(szString)-1; (cpos>szString) && (*cpos==cClear); cpos--,cleared++)
470  *cpos=0x00;
471  return cleared;
472 }

References SLen().

Referenced by C4ObjectInfoCore::Default(), C4Application::ParseCommandLine(), and SGetModule().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SCopy() [1/2]

void SCopy ( const char *  szSource,
char *  sTarget 
)

Definition at line 163 of file Standard.cpp.

164 {
165  if (szSource == sTarget) return;
166  if (!sTarget) return;
167  *sTarget=0;
168  if (!szSource) return;
169  strcpy(sTarget,szSource);
170 }

◆ SCopy() [2/2]

void SCopy ( const char *  szSource,
char *  sTarget,
size_t  iMaxL 
)

Definition at line 152 of file Standard.cpp.

153 {
154  if (szSource == sTarget) return;
155  if (!sTarget) return;
156  *sTarget=0;
157  if (!szSource) return;
158  while (*szSource && (iMaxL>0))
159  { *sTarget=*szSource; iMaxL--; szSource++; sTarget++; }
160  *sTarget=0;
161 }

Referenced by C4Group::AccessEntry(), C4Group::AccessNextEntry(), C4MainMenu::ActivateNewPlayer(), C4MainMenu::ActivateSavegame(), C4NameList::Add(), C4MessageInput::AddCommand(), CStdFile::Append(), C4Config::AtExePath(), C4Config::AtNetworkPath(), C4Config::AtScreenshotPath(), C4Config::AtSystemDataPath(), C4Config::AtTempPath(), C4Config::AtTempUpdatePath(), C4Config::AtUserDataPath(), CStdFont::BreakMessage(), C4AdditionalDefGraphics::C4AdditionalDefGraphics(), C4DefGraphicsPtrBackupEntry::C4DefGraphicsPtrBackupEntry(), C4Group_CopyItem(), C4Group_MoveItem(), C4Group_PackDirectory(), C4Group_PackDirectoryTo(), C4Group_SetTempPath(), C4Group_UnpackDirectory(), C4MCOverlay::C4MCOverlay(), C4MenuItem::C4MenuItem(), C4PortraitSelDlg::C4PortraitSelDlg(), C4StartupPlrPropertiesDlg::C4StartupPlrPropertiesDlg(), C4Team::C4Team(), C4Network2Res::CalculateSHA(), CopyDirectory(), CStdFile::Create(), C4Network2ResList::CreateNetworkFolder(), C4ConfigGeneral::CreateSaveFolder(), C4TeamList::CreateTeam(), C4ToolsDlg::Default(), C4ObjectInfoCore::Default(), C4PlayerInfoCore::Default(), C4ConfigGeneral::DefaultLanguage(), C4Player::DefaultRuntimeData(), C4Network2Res::Derive(), C4ConfigGeneral::DeterminePaths(), DirectoryExists(), C4StartupNetDlg::DoOK(), C4MainMenu::DoRefillInternal(), C4Game::DrawCrewOverheadText(), CStdFont::DrawText(), EnforceExtension(), C4Menu::Enter(), EraseDirectory(), C4UpdatePackage::Execute(), C4Config::ExpandEnvironmentVariables(), C4Group::ExtractEntry(), C4Command::Fail(), C4PlayerList::FileInUse(), C4Group::FindEntry(), C4SoundSystem::FindInstance(), C4Group::FindNextEntry(), C4GroupSet::FindSuitableFile(), C4Network2ResList::FindTempResFileName(), C4Network2Res::FinishDerive(), C4GraphicsSystem::FlashMessage(), ForEachFile(), C4GUI::Edit::GetCurrentWord(), C4SoundSystem::GetEffect(), GetFilenameOnly(), C4Language::GetPackGroups(), GetParentPath(), C4Network2Res::GetStandalone(), CStdFont::GetTextExtent(), C4Game::Init(), C4MusicFile::Init(), C4RankSystem::Init(), CStdFont::Init(), C4Player::Init(), C4Network2::Join(), C4ObjectInfo::Load(), C4Surface::Load(), C4FacetSurface::Load(), C4DefGraphics::Load(), C4Player::Load(), C4SoundEffect::Load(), C4StartupPlrSelDlg::PlayerListItem::Load(), C4Surface::LoadAny(), C4MusicSystem::LoadDir(), C4GameResList::LoadFoldersWithLocalDefs(), C4Game::LoadScenarioComponents(), C4Game::LoadScenarioSection(), main(), MakeFilenameFromTitle(), C4Config::MakeTempUpdateFolder(), C4UpdatePackage::MakeUpdate(), C4ObjectInfoList::MakeValidName(), C4MainMenu::MenuCommand(), C4Player::Message(), C4UpdatePackage::MkUp(), C4StartupPlrPropertiesDlg::OnClosed(), C4ChatControl::OnConnectBtn(), C4StartupMainDlg::OnNetJoin(), C4GameOptionButtons::OnPasswordSet(), C4StartupMainDlg::OnPlayerSelContextAddPlr(), C4Group::Open(), CStdFile::Open(), C4Group::OpenAsChild(), C4Game::OpenScenario(), StdStringAdapt::operator=(), C4Network2Res::OptimizeStandalone(), C4Application::ParseCommandLine(), C4MCParser::ParseFile(), C4MCParser::ParseMemFile(), C4MusicSystem::Play(), C4MessageInput::ProcessInput(), C4PlayerInfoCore::Promote(), C4Game::QuickSave(), RealPath(), C4GroupSet::RegisterParentFolders(), C4Group::Rename(), C4ScenarioListLoader::Entry::RenameTo(), C4LangStringTable::ReplaceStrings(), SAppend(), C4Player::Save(), C4Group::Save(), C4ObjectInfo::Save(), C4Landscape::P::SaveInternal(), C4Surface::SavePNG(), C4Console::SaveScenario(), SCopyEnclosed(), C4NameList::Set(), C4GroupEntry::Set(), C4GameControlClient::Set(), C4GraphicsOverlay::Set(), C4ToolsDlg::SetBackMaterial(), C4ToolsDlg::SetBackTexture(), C4Network2Res::SetByFile(), C4Network2Res::SetByGroup(), SetClientPrefix(), C4Network2Res::SetDerived(), C4MCOverlay::SetField(), C4Application::SetGameFont(), C4ToolsDlg::SetIFT(), C4Network2Res::SetLoad(), C4ToolsDlg::SetMaterial(), C4SDefinitions::SetModules(), C4Game::SetScenarioFilename(), C4GUI::ComboBox::SetText(), C4ToolsDlg::SetTexture(), C4Record::Start(), C4StartupScenSelDlg::StartScenario(), C4MessageInput::StoreBackBuffer(), C4Playback::StreamToRecord(), StdCompilerINIRead::String(), and C4InVal::ValidateString().

◆ SCopyEnclosed()

bool SCopyEnclosed ( const char *  szSource,
char  cOpen,
char  cClose,
char *  sTarget,
int  iSize 
)

Definition at line 529 of file Standard.cpp.

530 {
531  int iPos,iLen;
532  if (!szSource || !sTarget) return false;
533  if ((iPos = SCharPos(cOpen,szSource)) < 0) return false;
534  if ((iLen = SCharPos(cClose,szSource+iPos+1)) < 0) return false;
535  SCopy(szSource+iPos+1,sTarget,std::min(iLen,iSize));
536  return true;
537 }
int SCharPos(char cTarget, const char *szInStr, int iIndex)
Definition: Standard.cpp:239
int iSize
Definition: TstC4NetIO.cpp:32

References iSize, SCharPos(), and SCopy().

Referenced by C4Markup::Read().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SCopyIdentifier()

void SCopyIdentifier ( const char *  szSource,
char *  sTarget,
int  iMaxL = 0 
)

Definition at line 449 of file Standard.cpp.

450 {
451  if (!szSource || !sTarget) return;
452  while (IsIdentifier(*szSource))
453  {
454  if (iMaxL==1) { *sTarget++ = *szSource++; break; }
455  iMaxL--;
456  *sTarget++ = *szSource++;
457  }
458  *sTarget=0;
459 }
bool IsIdentifier(char cChar)
Definition: Standard.cpp:90

References IsIdentifier().

Referenced by C4MaterialMap::LoadEnumeration().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SCopySegment()

bool SCopySegment ( const char *  fstr,
int  segn,
char *  tstr,
char  sepa = ';',
int  iMaxL = -1,
bool  fSkipWhitespace = false 
)

Definition at line 279 of file Standard.cpp.

281 {
282  // Advance to indexed segment
283  while (iSegment>0)
284  {
285  if (SCharPos(cSeparator,szString) == -1)
286  { sTarget[0]=0; return false; }
287  szString += SCharPos(cSeparator,szString)+1;
288  iSegment--;
289  }
290  // Advance whitespace
291  if (fSkipWhitespace)
292  szString = SAdvanceSpace(szString);
293  // Copy segment contents
294  SCopyUntil(szString,sTarget,cSeparator,iMaxL);
295  return true;
296 }
const char * SAdvanceSpace(const char *szSPos)
Definition: Standard.cpp:420
void SCopyUntil(const char *szSource, char *sTarget, char cUntil, int iMaxL, int iIndex)
Definition: Standard.cpp:172

References SAdvanceSpace(), SCharPos(), and SCopyUntil().

Referenced by C4Group_IsExcluded(), C4ObjectInfoCore::Default(), C4Group::Delete(), C4UpdatePackage::DoGrpUpdate(), C4Group::Extract(), C4ConfigGeneral::GetLanguageSequence(), C4ComponentHost::GetLanguageString(), C4Game::GetTranslatedString(), C4Extra::Init(), C4RankSystem::Init(), C4FontLoader::InitFont(), C4GameResList::Load(), C4ComponentHost::Load(), C4SoundSystem::LoadEffects(), C4Language::LoadLanguage(), C4MainMenu::MenuCommand(), C4Group::Merge(), C4StartupMainDlg::OnPlayerSelContextRemove(), C4StartupMainDlg::OnPlayerSelContextRemovePlr(), RegisterShellExtensions(), SGetModule(), SortRank(), UnregisterShellExtensions(), and C4StartupMainDlg::UpdateParticipants().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SCopySegmentEx()

bool SCopySegmentEx ( const char *  fstr,
int  segn,
char *  tstr,
char  sepa1,
char  sepa2,
int  iMaxL = -1,
bool  fSkipWhitespace = false 
)

Definition at line 298 of file Standard.cpp.

300 {
301  // Advance to indexed segment
302  while (iSegment>0)
303  {
304  // use the separator that's closer
305  int iPos1 = SCharPos(cSep1,szString), iPos2 = SCharPos(cSep2,szString);
306  if (iPos1 == -1)
307  if (iPos2 == -1)
308  { sTarget[0]=0; return false; }
309  else
310  iPos1=iPos2;
311  else if (iPos2 != -1 && iPos2 < iPos1)
312  iPos1 = iPos2;
313  szString += iPos1+1;
314  iSegment--;
315  }
316  // Advance whitespace
317  if (fSkipWhitespace)
318  szString = SAdvanceSpace(szString);
319  // Copy segment contents; use separator that's closer
320  int iPos1 = SCharPos(cSep1,szString), iPos2 = SCharPos(cSep2,szString);
321  if (iPos2 != -1 && (iPos2 < iPos1 || iPos1 == -1)) cSep1 = cSep2;
322  SCopyUntil(szString,sTarget,cSep1,iMaxL);
323  return true;
324 }

References SAdvanceSpace(), SCharPos(), and SCopyUntil().

Referenced by C4Draw::TextOut().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SCopyUntil() [1/2]

void SCopyUntil ( const char *  szSource,
char *  sTarget,
char  cUntil,
int  iMaxL = -1,
int  iIndex = 0 
)

Definition at line 172 of file Standard.cpp.

173 {
174  if (szSource == sTarget) return;
175  if (!sTarget) return;
176  *sTarget=0;
177  if (!szSource) return;
178  while ( *szSource && ((*szSource!=cUntil) || (iIndex>0)) && (iMaxL!=0) )
179  { *sTarget=*szSource; if (*szSource==cUntil) iIndex--; szSource++; sTarget++; iMaxL--; }
180  *sTarget=0;
181 }

Referenced by C4FontLoader::InitFont(), C4MusicSystem::LoadMoreMusic(), C4Group::OpenAsChild(), C4MessageInput::ProcessCommand(), C4MessageInput::ProcessInput(), C4Game::QuickSave(), C4LangStringTable::ReplaceStrings(), C4GameSave::SaveDesc(), SCopySegment(), and SCopySegmentEx().

Here is the caller graph for this function:

◆ SCopyUntil() [2/2]

void SCopyUntil ( const char *  szSource,
char *  sTarget,
const char *  sUntil,
size_t  iMaxL 
)

Definition at line 183 of file Standard.cpp.

184 {
185  size_t n = std::min(strcspn(szSource, sUntil), iMaxL - 1);
186  strncpy(sTarget, szSource, n);
187  sTarget[n] = 0;
188 }

◆ SDelete()

void SDelete ( char *  szString,
int  iLen,
int  iPosition = 0 
)

Definition at line 521 of file Standard.cpp.

522 {
523  // Safety
524  if (!szString) return;
525  // Move down string remainder
526  MemCopy( szString+iPosition+iLen, szString+iPosition, SLen(szString+iPosition+iLen)+1 );
527 }
void MemCopy(const void *lpMem1, void *lpMem2, size_t dwSize)
Definition: Standard.h:65

References MemCopy(), and SLen().

Referenced by SRemoveModule().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SEqual()

bool SEqual ( const char *  szStr1,
const char *  szStr2 
)
inline

Definition at line 93 of file Standard.h.

93 { return szStr1&&szStr2?!std::strcmp(szStr1,szStr2):false; }

Referenced by C4ToolsDlg::AssertValidBackTexture(), C4ToolsDlg::AssertValidTexture(), C4FindObjectAction::Check(), C4Network2Res::Clear(), CommandByName(), C4MaterialReaction::CompileFunc(), CopyDirectory(), C4PlayerList::CtrlRemoveAtClient(), C4Network2Res::Derive(), C4UpdatePackage::DoGrpUpdate(), C4UpdatePackage::DoUpdate(), EraseDirectory(), C4UpdatePackage::Execute(), C4PlayerControlDefs::FinalInit(), C4GUI::ComboBox_FillCB::FindEntry(), C4MCOverlay::GetAlgo(), C4PlayerControlAssignmentSet::GetAssignmentByControlName(), C4PlayerList::GetByName(), C4Network2ClientList::GetClient(), C4ClientList::getClientByName(), C4MessageInput::GetCommand(), C4PlayerControlDefs::GetControlIndexByIdentifier(), C4AulFuncMap::GetFirstFunc(), C4ValueMapNames::GetItemNr(), C4Landscape::P::GetMapColorIndex(), C4MCNode::GetNodeByName(), C4Network2ResList::getRes(), C4Network2Res::GetStandalone(), C4TeamList::GetTeamByName(), C4Network2IRCChannel::getUser(), C4Network2::HandleConn(), CStdFont::IsSameAs(), CStdFont::IsSameAsID(), C4StartupNetListEntry::IsSameHost(), ItemIdentical(), C4Network2::LeaguePlrAuth(), C4RankSystem::Load(), C4Config::Load(), C4MusicSystem::LoadMoreMusic(), C4MainMenu::MenuCommand(), C4PlayerControlAssignmentSet::MergeFrom(), C4UpdatePackage::MkUp(), C4ValueCompiler::Name(), C4Group::OpenAsChild(), C4GraphicsOverlay::operator==(), StdStringAdapt::operator==(), C4UpdatePackage::Optimize(), C4Network2Res::OptimizeStandalone(), C4AulParse::Parse_DoWhile(), C4AulParse::Parse_Expression(), C4AulParse::Parse_For(), C4AulParse::Parse_ForEach(), C4AulParse::Parse_If(), C4AulParse::Parse_PropList(), C4AulParse::Parse_Script(), C4AulParse::Parse_Statement(), C4AulParse::Parse_ToplevelFunctionDecl(), C4AulParse::Parse_Var(), C4MusicSystem::Play(), C4MessageInput::ProcessCommand(), ProcessGroup(), C4Markup::Read(), C4Shader::Refresh(), C4PlayerControlAssignmentSet::RemoveAssignmentByControlName(), C4PlayerControlAssignmentSets::RemoveSetByName(), C4ScenarioListLoader::Entry::RenameTo(), C4Group::Save(), C4StartupOptionsDlg::SaveConfig(), C4NameList::Set(), C4MCOverlay::SetField(), C4MCPoint::SetField(), C4ToolsDlg::SetMaterial(), C4ToolsDlg::SetTexture(), C4GUI::Dialog::SetTitle(), C4ScenarioListLoader::Entry::SetTitleInGroup(), SIsModule(), C4MaterialMap::SortEnumeration(), C4MessageInput::StoreBackBuffer(), TexColSingle(), and C4LeagueSignupDialog::UserClose().

◆ SEqual2()

bool SEqual2 ( const char *  szStr1,
const char *  szStr2 
)

Definition at line 204 of file Standard.cpp.

205 {
206  if (!szStr1 || !szStr2) return false;
207  while (*szStr1 && *szStr2)
208  if (*szStr1++ != *szStr2++) return false;
209  if (*szStr2) return false; // Str1 is shorter
210  return true;
211 }

Referenced by C4GameMessage::Append(), StdCompilerINIRead::Boolean(), ConsoleDlgProc(), C4UpdatePackage::Execute(), C4MessageBoard::GetMessagePlayer(), GetRelativePathS(), GetTextSpecFacet(), C4Game::Init(), C4StartupScenSelDlg::KeyCheat2(), C4TextureMap::LoadFlags(), C4MainMenu::MenuCommand(), C4MainMenu::OnSelectionChanged(), C4MessageInput::ProcessCommand(), C4PlayerControlAssignment::ResolveRefs(), C4Console::SaveScenario(), and C4Network2RefServer::UnpackPacket().

Here is the caller graph for this function:

◆ SEqual2NoCase()

bool SEqual2NoCase ( const char *  szStr1,
const char *  szStr2,
int  iLen = -1 
)

Definition at line 226 of file Standard.cpp.

227 {
228  if (!szStr1 || !szStr2) return false;
229  if (iLen==0) return true;
230  while (*szStr1 && *szStr2)
231  {
232  if ( CharCapital(*szStr1++) != CharCapital(*szStr2++)) return false;
233  if (iLen>0) { iLen--; if (iLen==0) return true; }
234  }
235  if (*szStr2) return false; // Str1 is shorter
236  return true;
237 }

References CharCapital().

Referenced by C4ScenarioParameters::AddFilename2ID(), C4Application::DoInit(), C4DefList::GetByPath(), GetC4Filename(), GetRelativePathS(), C4Application::ParseCommandLine(), C4ChatControl::ProcessInput(), C4MessageInput::ProcessInput(), and C4Startup::SetStartScreen().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SEqualNoCase()

bool SEqualNoCase ( const char *  szStr1,
const char *  szStr2,
int  iLen = -1 
)

Definition at line 213 of file Standard.cpp.

214 {
215  if (!szStr1 || !szStr2) return false;
216  if (iLen==0) return true;
217  while (*szStr1 && *szStr2)
218  {
219  if ( CharCapital(*szStr1++) != CharCapital(*szStr2++)) return false;
220  if (iLen>0) { iLen--; if (iLen==0) return true; }
221  }
222  if (*szStr1 || *szStr2) return false;
223  return true;
224 }

References CharCapital().

Referenced by C4Record::AddFile(), C4TextureMap::CheckTexture(), C4Game::CreateSectionFromTempFile(), C4MaterialMap::CrossMapMaterials(), C4Game::DropFile(), C4PlayerList::FileInUse(), C4ScenarioListLoader::Folder::FindEntryByName(), C4Language::FindInfo(), C4PlayerInfoList::FindSavegameResumePlayerInfo(), C4DefGraphics::Get(), C4MaterialMap::Get(), C4PlayerInfoList::GetActivePlayerInfoByName(), C4PlayerList::GetAtClient(), C4Network2IRCClient::getChannel(), C4Network2Stats::GetGraphByName(), C4ScenarioSection::GetGroupfile(), C4ObjectInfoList::GetIdle(), C4TextureMap::GetIndex(), GetMusicFileTypeByExtension(), C4Language::GetPackGroups(), C4TextureMap::GetTexture(), C4TextureMap::GetTextureIndex(), C4StartupNetListEntry::IsSameRefQueryAddress(), C4LeagueResponseHead::isStatusRegister(), C4LeagueResponseHead::isSuccess(), ItemIdentical(), C4Network2::Join(), C4DefList::Load(), C4DefGraphics::Load(), C4ObjectInfo::Load(), C4MusicSystem::Load(), C4GameResList::LoadFoldersWithLocalDefs(), C4DefGraphics::LoadMesh(), C4Game::LoadScenarioSection(), C4DefGraphics::LoadSkeleton(), C4ObjectInfoList::NameExists(), C4Playback::Open(), C4Application::ParseCommandLine(), C4MessageInput::ProcessCommand(), C4ChatControl::ProcessInput(), C4MessageInput::ProcessInput(), C4Surface::Read(), C4GroupSet::RegisterParentFolders(), C4ScriptHost::ReloadScript(), C4Group::Rename(), C4ObjectInfo::Save(), C4ScenarioSection::ScenarioLoad(), SetClientPrefix(), C4Game::SetScenarioFilename(), C4Startup::SetStartScreen(), C4StartupOptionsDlg::SetSubscreen(), SIsModule(), C4KeyCodeEx::String2KeyShift(), C4StartupMainDlg::UpdateParticipants(), and C4InVal::ValidateString().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SEqualUntil()

bool SEqualUntil ( const char *  szStr1,
const char *  szStr2,
char  cWild 
)

Definition at line 190 of file Standard.cpp.

191 {
192  if (!szStr1 || !szStr2) return false;
193  while (*szStr1 || *szStr2)
194  {
195  if ((*szStr1==cWild) || (*szStr2==cWild)) return true;
196  if (*szStr1!=*szStr2) return false;
197  szStr1++; szStr2++;
198  }
199  return true;
200 }

◆ SGetLine()

int SGetLine ( const char *  szText,
const char *  cpPosition 
)

Definition at line 479 of file Standard.cpp.

480 {
481  if (!szText || !cpPosition) return 0;
482  int iLines = 1;
483  while (*szText && (szText<cpPosition))
484  {
485  if (*szText == 0x0A) iLines++;
486  szText++;
487  }
488  return iLines;
489 }

Referenced by C4AulParseError::C4AulParseError(), C4MCParserErr::C4MCParserErr(), C4AulScriptFunc::GetLineOfCode(), C4ScriptHost::Parse(), and C4AulScriptContext::ReturnDump().

Here is the caller graph for this function:

◆ SGetModule()

bool SGetModule ( const char *  szList,
int  iIndex,
char *  sTarget,
int  iSize = -1 
)

Definition at line 539 of file Standard.cpp.

540 {
541  if (!szList || !sTarget) return false;
542  if (!SCopySegment(szList,iIndex,sTarget,';',iSize)) return false;
543  SClearFrontBack(sTarget);
544  return true;
545 }
bool SCopySegment(const char *szString, int iSegment, char *sTarget, char cSeparator, int iMaxL, bool fSkipWhitespace)
Definition: Standard.cpp:279
int SClearFrontBack(char *szString, char cClear)
Definition: Standard.cpp:461

References iSize, SClearFrontBack(), and SCopySegment().

Referenced by C4ClientPlayerInfos::C4ClientPlayerInfos(), C4Group_ApplyUpdate(), SAddModules(), C4SDefinitions::SetModules(), C4MusicSystem::SetPlayList(), SIsModule(), SRemoveModules(), and C4GameSave::WriteDescDefinitions().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Sign()

template<class T >
int Sign ( val)
inline

Definition at line 45 of file Standard.h.

45 { return val < 0 ? -1 : val > 0 ? 1 : 0; }

Referenced by C4Object::DoMovement(), C4Weather::Execute(), C4Landscape::InsertMaterial(), RedirectForce(), and SimFlight().

Here is the caller graph for this function:

◆ SInsert()

void SInsert ( char *  szString,
const char *  szInsert,
int  iPosition = 0,
int  iMaxLen = -1 
)

Definition at line 509 of file Standard.cpp.

510 {
511  // Safety
512  if (!szString || !szInsert || !szInsert[0]) return;
513  size_t insertlen = strlen(szInsert);
514  if (iMaxLen >= 0 && strlen(szString) + insertlen > (size_t) iMaxLen) return;
515  // Move up string remainder
516  memmove (szString + iPosition + insertlen, szString + iPosition, SLen(szString+ iPosition) + 1);
517  // Copy insertion
518  MemCopy( szInsert, szString+iPosition, SLen(szInsert) );
519 }

References MemCopy(), and SLen().

Referenced by C4Group::GetFullName().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SIsModule()

bool SIsModule ( const char *  szList,
const char *  szString,
int *  ipIndex = nullptr,
bool  fCaseSensitive = false 
)

Definition at line 547 of file Standard.cpp.

548 {
549  char szModule[1024+1];
550  // Compare all modules
551  for (int iMod=0; SGetModule(szList,iMod,szModule,1024); iMod++)
552  if (fCaseSensitive ? SEqual(szString,szModule) : SEqualNoCase(szString,szModule))
553  {
554  // Provide index if desired
555  if (ipIndex) *ipIndex = iMod;
556  // Found
557  return true;
558  }
559  // Not found
560  return false;
561 }
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:213
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:93

References SEqual(), SEqualNoCase(), and SGetModule().

Referenced by C4Group_TestIgnore(), C4MapFolderData::CreateGUIElements(), C4FileSelDlg::GetSelection(), C4DefinitionSelDlg::IsItemGrayed(), C4Config::IsModule(), C4Game::JoinPlayer(), C4ScenarioListLoader::Scenario::LoadCustomPre(), C4StartupMainDlg::OnPlayerSelContextAdd(), C4Game::OpenScenario(), SAddModule(), C4FileSelDlg::SetSelection(), and SRemoveModule().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SLen()

size_t SLen ( const char *  sptr)
inline

Definition at line 74 of file Standard.h.

74 { return sptr?std::strlen(sptr):0; }

Referenced by C4MainMenu::ActivateSavegame(), C4GameMessage::Append(), AppendBackslash(), C4Group_CopyItem(), C4Group_MoveItem(), C4RankSystem::Check(), C4ConfigGeneral::DeterminePaths(), DirectoryExists(), C4GUI::Edit::DrawElement(), C4Config::ExpandEnvironmentVariables(), C4Console::FileOpenWPlrs(), C4GraphicsSystem::FlashMessage(), C4DefList::GetByPath(), C4Language::GetPackGroups(), GetRelativePathS(), GetTrailingNumber(), C4GUI::Edit::InsertText(), C4MaterialMap::LoadEnumeration(), C4TextureMap::LoadTextures(), LogSilent(), C4ObjectInfoList::MakeValidName(), C4Player::Message(), C4GUI::Edit::OnContext(), C4GUI::Edit::OnGetFocus(), C4Group::Open(), C4Group::OpenAsChild(), C4Application::ParseCommandLine(), C4Console::PlayerJoin(), C4MessageInput::ProcessInput(), C4HTTPClient::Query(), C4Game::QuickSave(), C4Markup::Read(), RealPath(), C4GroupSet::RegisterParentFolders(), C4LangStringTable::ReplaceStrings(), SAppend(), C4ObjectInfo::Save(), C4MaterialMap::SaveEnumeration(), SClearFrontBack(), SDelete(), C4GUI::Edit::SelectAll(), C4Network2Res::SetByCore(), SetClientPrefix(), C4Application::SetGameFont(), SInsert(), SRemoveModule(), SSearch(), SSearchNoCase(), C4Record::Start(), TruncateBackslash(), C4LeagueSignupDialog::UserClose(), and CStdFile::WriteString().

Here is the caller graph for this function:

◆ SLenUntil()

size_t SLenUntil ( const char *  szStr,
char  cUntil 
)
inline

Definition at line 75 of file Standard.h.

76 {
77  if (!szStr) return 0;
78  const char *end = std::strchr(szStr, cUntil);
79  return end ? end-szStr : std::strlen(szStr);
80 }

◆ SLineGetCharacters()

int SLineGetCharacters ( const char *  szText,
const char *  cpPosition 
)

Definition at line 491 of file Standard.cpp.

492 {
493  if (!szText || !cpPosition) return 0;
494  int iChars = 1;
495  while (*szText && (szText<cpPosition))
496  {
497  if (*szText == 0x0A)
498  iChars = 1;
499  else if (*szText == '\t')
500  // assume a tab stop every 8 characters
501  iChars = ((iChars - 1 + 8) & ~7) + 1;
502  else
503  iChars++;
504  szText++;
505  }
506  return iChars;
507 }

Referenced by C4AulParseError::C4AulParseError().

Here is the caller graph for this function:

◆ SModuleCount()

int SModuleCount ( const char *  szList)

Definition at line 617 of file Standard.cpp.

618 {
619  if (!szList) return 0;
620  int iCount = 0;
621  bool fNewModule = true;
622  while (*szList)
623  {
624  switch (*szList)
625  {
626  case ' ': break;
627  case ';': fNewModule=true; break;
628  default: if (fNewModule) iCount++; fNewModule=false; break;
629  }
630  szList++;
631  }
632  return iCount;
633 }

Referenced by C4ClientPlayerInfos::C4ClientPlayerInfos(), C4ScenarioListLoader::Scenario::CanOpen(), and C4SDefinitions::SetModules().

Here is the caller graph for this function:

◆ SNewSegment()

void SNewSegment ( char *  szStr,
const char *  szSepa = ";" 
)

Definition at line 474 of file Standard.cpp.

475 {
476  if (szStr[0]) SAppend(szSepa,szStr);
477 }

References SAppend().

Referenced by SAddModule().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SRemoveModule()

bool SRemoveModule ( char *  szList,
const char *  szModule,
bool  fCaseSensitive = false 
)

Definition at line 588 of file Standard.cpp.

589 {
590  int iMod,iPos,iLen;
591  // Not a module
592  if (!SIsModule(szList,szModule,&iMod,fCaseSensitive)) return false;
593  // Get module start
594  iPos = 0;
595  if (iMod > 0) iPos = SCharPos(';',szList,iMod-1)+1;
596  // Get module length
597  iLen = SCharPos(';',szList+iPos);
598  if (iLen<0) iLen=SLen(szList); else iLen+=1;
599  // Delete module
600  SDelete(szList,iLen,iPos);
601  // Success
602  return true;
603 }
void SDelete(char *szString, int iLen, int iPosition)
Definition: Standard.cpp:521

References SCharPos(), SDelete(), SIsModule(), and SLen().

Referenced by C4StartupMainDlg::OnPlayerSelContextRemovePlr(), C4Config::RemoveModule(), and SRemoveModules().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SRemoveModules()

bool SRemoveModules ( char *  szList,
const char *  szModules,
bool  fCaseSensitive = false 
)

Definition at line 605 of file Standard.cpp.

606 {
607  // Safety / no empties
608  if (!szList || !szModules || !szModules[0]) return false;
609  // Remove modules
610  char szModule[1024+1]; // limited
611  for (int cnt=0; SGetModule(szModules,cnt,szModule,1024); cnt++)
612  SRemoveModule(szList,szModule,fCaseSensitive);
613  // Success
614  return true;
615 }
bool SRemoveModule(char *szList, const char *szModule, bool fCaseSensitive)
Definition: Standard.cpp:588

References SGetModule(), and SRemoveModule().

Referenced by C4StartupScenSelDlg::KeyCheat2().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SReplaceChar()

void SReplaceChar ( char *  str,
char  fc,
char  tc 
)

Definition at line 354 of file Standard.cpp.

355 {
356  while (str && *str)
357  { if (*str==fc) *str=tc; str++; }
358 }

Referenced by C4MenuItem::C4MenuItem(), C4StartupPlrSelDlg::CheckPlayerName(), C4NetFilenameAdapt::CompileFunc(), C4ObjectInfoCore::Default(), C4ComponentHost::Load(), C4TextureMap::LoadTextures(), C4Group::Open(), C4Application::ParseCommandLine(), and C4LangStringTable::ReplaceStrings().

Here is the caller graph for this function:

◆ SSearch()

const char* SSearch ( const char *  szString,
const char *  szIndex 
)

Definition at line 369 of file Standard.cpp.

370 {
371  const char *cscr;
372  size_t indexlen,match=0;
373  if (!szString || !szIndex) return nullptr;
374  indexlen=SLen(szIndex);
375  for (cscr=szString; cscr && *cscr; cscr++)
376  {
377  if (*cscr==szIndex[match]) match++;
378  else match=0;
379  if (match>=indexlen) return cscr+1;
380  }
381  return nullptr;
382 }

References SLen().

Referenced by C4ClientPlayerInfos::C4ClientPlayerInfos(), C4DownloadDlg::DownloadFile(), C4Config::ExpandEnvironmentVariables(), C4TextureMap::GetIndexMatTex(), C4ComponentHost::GetLanguageString(), C4ComponentHost::Load(), C4MusicSystem::LoadDir(), C4MaterialMap::LoadEnumeration(), C4TextureMap::LoadFlags(), C4Player::LoadRuntimeData(), LogFatal(), C4MessageInput::ProcessCommand(), StdStrBuf::Replace(), C4LangStringTable::ReplaceStrings(), C4Landscape::SetTextureIndex(), and C4Markup::StripMarkup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SSearchNoCase()

const char* SSearchNoCase ( const char *  szString,
const char *  szIndex 
)

Definition at line 384 of file Standard.cpp.

385 {
386  const char *cscr;
387  size_t indexlen,match=0;
388  if (!szString || !szIndex) return nullptr;
389  indexlen=SLen(szIndex);
390  for (cscr=szString; cscr && *cscr; cscr++)
391  {
392  if (CharCapital(*cscr)==CharCapital(szIndex[match])) match++;
393  else match=0;
394  if (match>=indexlen) return cscr+1;
395  }
396  return nullptr;
397 }

References CharCapital(), and SLen().

Referenced by C4StartupNetListEntry::KeywordMatch().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ssprintf()

template<size_t N>
int ssprintf ( char(&)  str[N],
const char *  fmt,
  ... 
)
inline

Definition at line 165 of file Standard.h.

166 {
167  va_list args; va_start(args, fmt);
168  int m = vsnprintf(str, N, fmt, args);
169  // Quick exit if vsnprintf failed
170  if (m < 0) return m;
171  if (static_cast<size_t>(m) >= N) { m = N-1; str[m] = 0; }
172  return m;
173 }

◆ strprintf()

std::string strprintf ( const char *  format,
  ... 
)

Definition at line 838 of file Standard.cpp.

839 {
840  va_list args;
841  va_start(args, format);
842  std::string s = vstrprintf(format, args);
843  va_end(args);
844  return s;
845 }
std::string vstrprintf(const char *format, va_list args)
Definition: Standard.cpp:822

References s, and vstrprintf().

Referenced by C4GUI::MessageDialog::MessageDialog().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ StrToI32()

int32_t StrToI32 ( const char *  s,
int  base,
const char **  scan_end 
)

Definition at line 120 of file Standard.cpp.

121 {
122  const char *s = str;
123  int sign = 1;
124  int32_t result = 0;
125  if (*s == '-')
126  {
127  sign = -1;
128  s++;
129  }
130  else if (*s == '+')
131  {
132  s++;
133  }
134  if (!*s)
135  {
136  // Abort if there are no digits to parse
137  if (scan_end) *scan_end = str;
138  return 0;
139  }
140  while (IsNumber(*s,base))
141  {
142  int value = ToNumber(*s++);
143  assert (value < base && value >= 0);
144  result *= base;
145  result += value;
146  }
147  if (scan_end != nullptr) *scan_end = s;
148  result *= sign;
149  return result;
150 }

References s.

◆ SWildcardMatchEx()

bool SWildcardMatchEx ( const char *  szString,
const char *  szWildcard 
)

Definition at line 635 of file Standard.cpp.

636 {
637  // safety
638  if (!szString || !szWildcard) return false;
639  // match char-wise
640  const char *pWild = szWildcard, *pPos = szString;
641  const char *pLWild = nullptr, *pLPos = nullptr; // backtracking
642  while (*pWild || pLWild)
643  // string wildcard?
644  if (*pWild == '*')
645  { pLWild = ++pWild; pLPos = pPos; }
646  // nothing left to match?
647  else if (!*pPos)
648  break;
649  // equal or one-character-wildcard? proceed
650  else if (*pWild == '?' || *pWild == *pPos)
651  { pWild++; pPos++; }
652  // backtrack possible?
653  else if (pLPos)
654  { pWild = pLWild; pPos = ++pLPos; }
655  // match failed
656  else
657  return false;
658  // match complete if both strings are fully matched
659  return !*pWild && !*pPos;
660 }

Referenced by C4Effect::Get(), C4Effect::GetCount(), C4Network2IRCClient::Join(), and StdMeshMaterialSubLoader::Load().

Here is the caller graph for this function:

◆ SWordWrap()

void SWordWrap ( char *  szText,
char  cSpace,
char  cSepa,
int  iMaxLine 
)

Definition at line 399 of file Standard.cpp.

400 {
401  if (!szText) return;
402  // Scan string
403  char *cPos,*cpLastSpace=nullptr;
404  int iLineRun=0;
405  for (cPos=szText; *cPos; cPos++)
406  {
407  // Store last space
408  if (*cPos==cSpace) cpLastSpace=cPos;
409  // Separator encountered: reset line run
410  if (*cPos==cSepa) iLineRun=0;
411  // Need a break, insert at last space
412  if (iLineRun>=iMaxLine)
413  if (cpLastSpace)
414  { *cpLastSpace=cSepa; iLineRun=cPos - cpLastSpace; }
415  // Line run
416  iLineRun++;
417  }
418 }

Referenced by C4Game::DrawCrewOverheadText().

Here is the caller graph for this function:

◆ vstrprintf()

std::string vstrprintf ( const char *  format,
va_list  args 
)

Definition at line 822 of file Standard.cpp.

823 {
824  va_list argcopy;
825  va_copy(argcopy, args);
826  int size = vsnprintf(nullptr, 0, format, argcopy);
827  if (size < 0)
828  throw std::invalid_argument("invalid argument to strprintf");
829  va_end(argcopy);
830  std::string s;
831  s.resize(size + 1);
832  size = vsnprintf(&s[0], s.size(), format, args);
833  assert(size >= 0);
834  s.resize(size);
835  return s;
836 }

References s.

Referenced by strprintf().

Here is the caller graph for this function:

◆ ZeroMem()

template<class T >
std::enable_if<std::is_pod<T>::value>::type ZeroMem ( T *  lpMem,
size_t  dwSize 
)
inline