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 LineFeed   "\x00D\x00A"
 
#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

◆ LineFeed

◆ sprintf

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.

References Abs().

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

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
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.

References IsIdentifier().

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

70 { return std::toupper(cChar); }
Here is the call graph for this function:
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.

Referenced by C4MapScriptAlgoLines::C4MapScriptAlgoLines(), DWordAligned(), 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().

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 }
Here is the caller graph for this function:

◆ DWordAligned()

int DWordAligned ( int  val)
inline

Definition at line 47 of file Standard.h.

References Angle(), Distance(), Pow(), s, and StrToI32().

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

48 {
49  if (val%4) { val>>=2; val<<=2; val+=4; }
50  return val;
51 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetCharacterCount()

int GetCharacterCount ( const char *  s)

Definition at line 785 of file Standard.cpp.

References s.

Referenced by GetNextCharacter().

786 {
787  int l = 0;
788  while (*s)
789  {
790  unsigned char c = *s;
791  if (c < 128 || c > 247)
792  {
793  ++l;
794  s += 1;
795  }
796  else if (c > 191 && c < 224)
797  {
798  ++l;
799  s += 2;
800  }
801  else if (c >= 224 && c <= 239)
802  {
803  ++l;
804  s += 3;
805  }
806  else if (c >= 240 && c <= 247)
807  {
808  ++l;
809  s += 4;
810  }
811  else assert(false);
812  }
813  return l;
814 }
#define s
Here is the caller graph for this function:

◆ GetNextCharacter()

uint32_t GetNextCharacter ( const char **  pszString)
inline

Definition at line 84 of file Standard.h.

References GetCharacterCount(), GetNextUTF8Character(), and s.

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

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:749
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 749 of file Standard.cpp.

Referenced by GetNextCharacter(), and SLenUntil().

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

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

36 {
37  obj->~T();
38  new (obj) T();
39 }
Here is the caller graph for this function:

◆ Inside()

◆ IsIdentifier()

bool IsIdentifier ( char  cChar)

Definition at line 90 of file Standard.cpp.

References Inside().

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

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
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 696 of file Standard.cpp.

Referenced by CStdFont::DrawText(), StdStrBuf::EnsureUnicode(), CStdFont::GetTextExtent(), C4GUI::IsWholeWordSpacer(), and ssprintf().

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

◆ IsWhiteSpace()

bool IsWhiteSpace ( char  cChar)
inline

Definition at line 72 of file Standard.h.

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

72 { return !!std::isspace((unsigned char)cChar); }
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.

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

66 {
67  std::memmove(lpMem2,lpMem1,dwSize);
68 }
Here is the caller graph for this function:

◆ osprintf()

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

Definition at line 157 of file Standard.h.

Referenced by MakeTempFilename().

158 {
159  va_list args; va_start(args, fmt);
160  return vsprintf(str, fmt, args);
161 }
Here is the caller graph for this function:

◆ Pow()

int Pow ( int  base,
int  exponent 
)

Definition at line 69 of file Standard.cpp.

Referenced by C4AulExec::ClearPointers(), DWordAligned(), and C4AulCompiler::ConstexprEvaluator::visit().

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 }
Here is the caller graph for this function:

◆ SAddModule()

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

Definition at line 557 of file Standard.cpp.

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

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

558 {
559  // Safety / no empties
560  if (!szList || !szModule || !szModule[0]) return false;
561  // Already a module?
562  if (SIsModule(szList,szModule,nullptr,fCaseSensitive)) return false;
563  // New segment, add string
564  SNewSegment(szList);
565  SAppend(szModule,szList);
566  // Success
567  return true;
568 }
void SAppend(const char *szSource, char *szTarget, int iMaxL)
Definition: Standard.cpp:257
bool SIsModule(const char *szList, const char *szString, int *ipIndex, bool fCaseSensitive)
Definition: Standard.cpp:541
void SNewSegment(char *szStr, const char *szSepa)
Definition: Standard.cpp:468
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 570 of file Standard.cpp.

References SAddModule(), and SGetModule().

Referenced by C4StartupScenSelDlg::KeyCheat2(), and SEqual().

571 {
572  // Safety / no empties
573  if (!szList || !szModules || !szModules[0]) return false;
574  // Add modules
575  char szModule[1024+1]; // limited
576  for (int cnt=0; SGetModule(szModules,cnt,szModule,1024); cnt++)
577  SAddModule(szList,szModule,fCaseSensitive);
578  // Success
579  return true;
580 }
bool SGetModule(const char *szList, int iIndex, char *sTarget, int iSize)
Definition: Standard.cpp:533
bool SAddModule(char *szList, const char *szModule, bool fCaseSensitive)
Definition: Standard.cpp:557
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 432 of file Standard.cpp.

Referenced by C4GameMessage::Append(), and SEqual().

433 {
434  if (!szSPos) return nullptr;
435  while (*szSPos)
436  {
437  if (*szSPos==cPast) { szSPos++; break; }
438  szSPos++;
439  }
440  return szSPos;
441 }
Here is the caller graph for this function:

◆ SAdvanceSpace()

const char* SAdvanceSpace ( const char *  szSPos)

Definition at line 414 of file Standard.cpp.

References IsWhiteSpace().

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

415 {
416  if (!szSPos) return nullptr;
417  while (IsWhiteSpace(*szSPos)) szSPos++;
418  return szSPos;
419 }
bool IsWhiteSpace(char cChar)
Definition: Standard.h:72
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 257 of file Standard.cpp.

References SCopy(), and SLen().

Referenced by C4Group::AccessNextEntry(), 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(), C4SoundEffect::Load(), C4DefGraphics::Load(), C4Group::Merge(), C4UpdatePackage::MkUp(), C4StartupPlrSelDlg::PlayerListItem::MoveFilename(), C4Group::Open(), RealPath(), C4Group::Rename(), C4ScenarioListLoader::Entry::RenameTo(), SAddModule(), C4ObjectInfo::Save(), C4Group::Save(), C4MaterialMap::SaveEnumeration(), C4Surface::SavePNG(), SEqual(), SetClientPrefix(), C4StartupOptionsDlg::SetSubscreen(), SNewSegment(), C4Playback::StreamToRecord(), and C4ObjectList::Write().

258 {
259  if (iMaxL == -1)
260  SCopy(szSource, szTarget + SLen(szTarget));
261  else
262  SCopy(szSource, szTarget + SLen(szTarget), iMaxL - SLen(szTarget));
263 }
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:152
size_t SLen(const char *sptr)
Definition: Standard.h:74
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 265 of file Standard.cpp.

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

266 {
267  if (!szStr) return;
268  char *cPos;
269  for (cPos=szStr; *cPos; cPos++) {}
270  *cPos=cChar; *(cPos+1)=0;
271 }
Here is the caller graph for this function:

◆ SCapitalize()

void SCapitalize ( char *  szString)

Definition at line 354 of file Standard.cpp.

References CharCapital().

Referenced by C4Language::LoadComponentHost(), C4ChatInputDialog::OnChatInput(), and SEqual().

355 {
356  while (str && *str)
357  {
358  *str=CharCapital(*str);
359  str++;
360  }
361 }
char CharCapital(char cChar)
Definition: Standard.h:70
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 320 of file Standard.cpp.

References iResult.

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

321 {
322  unsigned int iResult=0;
323  // Scan string
324  while (*szInStr)
325  {
326  // End position reached (end character is not included)
327  if (szInStr==cpUntil) return iResult;
328  // Character found
329  if (*szInStr==cTarget) iResult++;
330  // Advance
331  szInStr++;
332  }
333  // Done
334  return iResult;
335 }
int iResult
Definition: C4GroupMain.cpp:39
Here is the caller graph for this function:

◆ SCharCountEx()

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

Definition at line 337 of file Standard.cpp.

References iResult, and SCharCount().

Referenced by SEqual(), and C4LeagueSignupDialog::UserClose().

338 {
339  unsigned int iResult = 0;
340  while ( *szCharList )
341  {
342  iResult += SCharCount( *szCharList, szString );
343  szCharList++;
344  }
345  return iResult;
346 }
unsigned int SCharCount(char cTarget, const char *szInStr, const char *cpUntil)
Definition: Standard.cpp:320
int iResult
Definition: C4GroupMain.cpp:39
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 247 of file Standard.cpp.

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

248 {
249  const char *cpos;
250  int ccpos,lcpos;
251  if (!szInStr) return -1;
252  for (cpos=szInStr,ccpos=0,lcpos=-1; *cpos; cpos++,ccpos++)
253  if (*cpos==cTarget) lcpos=ccpos;
254  return lcpos;
255 }
Here is the caller graph for this function:

◆ SCharPos()

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

Definition at line 233 of file Standard.cpp.

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

234 {
235  const char *cpos;
236  int ccpos;
237  if (!szInStr) return -1;
238  for (cpos=szInStr,ccpos=0; *cpos; cpos++,ccpos++)
239  if (*cpos==cTarget)
240  {
241  if (iIndex==0) return ccpos;
242  else iIndex--;
243  }
244  return -1;
245 }
Here is the caller graph for this function:

◆ SClearFrontBack()

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

Definition at line 455 of file Standard.cpp.

References SLen().

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

456 {
457  int cleared=0;
458  char *cpos;
459  if (!szString) return 0;
460  for (cpos=szString; *cpos && (*cpos==cClear); cpos++,cleared++) {}
461  // strcpy is undefined when used on overlapping strings...
462  if (cpos!=szString) memmove(szString, cpos, SLen(cpos) + 1);
463  for (cpos=szString+SLen(szString)-1; (cpos>szString) && (*cpos==cClear); cpos--,cleared++)
464  *cpos=0x00;
465  return cleared;
466 }
size_t SLen(const char *sptr)
Definition: Standard.h:74
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 161 of file Standard.cpp.

Referenced by SEqual().

162 {
163  if (szSource == sTarget) return;
164  if (!sTarget) return; *sTarget=0; if (!szSource) return;
165  strcpy(sTarget,szSource);
166 }
Here is the caller graph for this function:

◆ SCopy() [2/2]

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

Definition at line 152 of file Standard.cpp.

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(), C4Group::Clear(), C4Def::Clear(), C4MCParser::Clear(), CopyDirectory(), CStdFile::Create(), C4Network2ResList::CreateNetworkFolder(), C4ConfigGeneral::CreateSaveFolder(), C4TeamList::CreateTeam(), C4ObjectInfoCore::Default(), C4ToolsDlg::Default(), C4PlayerInfoCore::Default(), C4ConfigGeneral::DefaultLanguage(), C4Player::DefaultRuntimeData(), C4Network2Res::Derive(), C4ConfigGeneral::DeterminePaths(), DirectoryExists(), C4Menu::DoInitRefSym(), 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(), C4MusicFile::Init(), C4RankSystem::Init(), CStdFont::Init(), C4Game::Init(), C4Player::Init(), C4GUI::Edit::InsertText(), C4Network2::Join(), C4SoundEffect::Load(), C4ObjectInfo::Load(), C4FacetSurface::Load(), C4DefGraphics::Load(), C4StartupPlrSelDlg::PlayerListItem::Load(), C4Surface::Load(), C4Player::Load(), C4Surface::LoadAny(), C4Language::LoadComponentHost(), C4MusicSystem::LoadDir(), C4GameResList::LoadFoldersWithLocalDefs(), C4Game::LoadScenarioComponents(), C4Game::LoadScenarioSection(), main(), MakeFilenameFromTitle(), C4Config::MakeTempUpdateFolder(), C4UpdatePackage::MakeUpdate(), C4ObjectInfoList::MakeValidName(), C4MainMenu::MenuCommand(), C4Group::Merge(), C4Player::Message(), C4UpdatePackage::MkUp(), C4StartupPlrSelDlg::PlayerListItem::MoveFilename(), C4StartupPlrPropertiesDlg::OnClosed(), C4ChatControl::OnConnectBtn(), C4StartupMainDlg::OnNetJoin(), C4GameOptionButtons::OnPasswordSet(), C4StartupMainDlg::OnPlayerSelContextAddPlr(), CStdFile::Open(), C4Group::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(), C4ValueMapNames::Reset(), SAppend(), C4ObjectInfo::Save(), C4Group::Save(), C4Player::Save(), C4Landscape::P::SaveInternal(), C4Surface::SavePNG(), C4Console::SaveScenario(), SCopyEnclosed(), C4NameList::Set(), C4GroupEntry::Set(), C4GraphicsOverlay::Set(), C4GameControlClient::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(), C4StartupOptionsDlg::SetSubscreen(), C4GUI::ComboBox::SetText(), C4ToolsDlg::SetTexture(), C4Record::Start(), C4StartupScenSelDlg::StartScenario(), C4MessageInput::StoreBackBuffer(), C4Playback::StreamToRecord(), StdCompilerINIRead::String(), and C4InVal::ValidateString().

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

◆ SCopyEnclosed()

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

Definition at line 523 of file Standard.cpp.

References SCharPos(), and SCopy().

Referenced by C4Markup::Read(), and SEqual().

524 {
525  int iPos,iLen;
526  if (!szSource || !sTarget) return false;
527  if ((iPos = SCharPos(cOpen,szSource)) < 0) return false;
528  if ((iLen = SCharPos(cClose,szSource+iPos+1)) < 0) return false;
529  SCopy(szSource+iPos+1,sTarget,std::min(iLen,iSize));
530  return true;
531 }
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:152
int SCharPos(char cTarget, const char *szInStr, int iIndex)
Definition: Standard.cpp:233
int iSize
Definition: TstC4NetIO.cpp:32
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 443 of file Standard.cpp.

References IsIdentifier().

Referenced by C4MaterialMap::LoadEnumeration(), and SEqual().

444 {
445  if (!szSource || !sTarget) return;
446  while (IsIdentifier(*szSource))
447  {
448  if (iMaxL==1) { *sTarget++ = *szSource++; break; }
449  iMaxL--;
450  *sTarget++ = *szSource++;
451  }
452  *sTarget=0;
453 }
bool IsIdentifier(char cChar)
Definition: Standard.cpp:90
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 273 of file Standard.cpp.

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

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

275 {
276  // Advance to indexed segment
277  while (iSegment>0)
278  {
279  if (SCharPos(cSeparator,szString) == -1)
280  { sTarget[0]=0; return false; }
281  szString += SCharPos(cSeparator,szString)+1;
282  iSegment--;
283  }
284  // Advance whitespace
285  if (fSkipWhitespace)
286  szString = SAdvanceSpace(szString);
287  // Copy segment contents
288  SCopyUntil(szString,sTarget,cSeparator,iMaxL);
289  return true;
290 }
const char * SAdvanceSpace(const char *szSPos)
Definition: Standard.cpp:414
int SCharPos(char cTarget, const char *szInStr, int iIndex)
Definition: Standard.cpp:233
void SCopyUntil(const char *szSource, char *sTarget, char cUntil, int iMaxL, int iIndex)
Definition: Standard.cpp:168
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 292 of file Standard.cpp.

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

Referenced by SEqual(), and C4Draw::TextOut().

294 {
295  // Advance to indexed segment
296  while (iSegment>0)
297  {
298  // use the separator that's closer
299  int iPos1 = SCharPos(cSep1,szString), iPos2 = SCharPos(cSep2,szString);
300  if (iPos1 == -1)
301  if (iPos2 == -1)
302  { sTarget[0]=0; return false; }
303  else
304  iPos1=iPos2;
305  else if (iPos2 != -1 && iPos2 < iPos1)
306  iPos1 = iPos2;
307  szString += iPos1+1;
308  iSegment--;
309  }
310  // Advance whitespace
311  if (fSkipWhitespace)
312  szString = SAdvanceSpace(szString);
313  // Copy segment contents; use separator that's closer
314  int iPos1 = SCharPos(cSep1,szString), iPos2 = SCharPos(cSep2,szString);
315  if (iPos2 != -1 && (iPos2 < iPos1 || iPos1 == -1)) cSep1 = cSep2;
316  SCopyUntil(szString,sTarget,cSep1,iMaxL);
317  return true;
318 }
const char * SAdvanceSpace(const char *szSPos)
Definition: Standard.cpp:414
int SCharPos(char cTarget, const char *szInStr, int iIndex)
Definition: Standard.cpp:233
void SCopyUntil(const char *szSource, char *sTarget, char cUntil, int iMaxL, int iIndex)
Definition: Standard.cpp:168
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 168 of file Standard.cpp.

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

169 {
170  if (szSource == sTarget) return;
171  if (!sTarget) return; *sTarget=0; if (!szSource) return;
172  while ( *szSource && ((*szSource!=cUntil) || (iIndex>0)) && (iMaxL!=0) )
173  { *sTarget=*szSource; if (*szSource==cUntil) iIndex--; szSource++; sTarget++; iMaxL--; }
174  *sTarget=0;
175 }
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 177 of file Standard.cpp.

178 {
179  size_t n = std::min(strcspn(szSource, sUntil), iMaxL - 1);
180  strncpy(sTarget, szSource, n);
181  sTarget[n] = 0;
182 }

◆ SDelete()

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

Definition at line 515 of file Standard.cpp.

References MemCopy(), and SLen().

Referenced by SEqual(), and SRemoveModule().

516 {
517  // Safety
518  if (!szString) return;
519  // Move down string remainder
520  MemCopy( szString+iPosition+iLen, szString+iPosition, SLen(szString+iPosition+iLen)+1 );
521 }
size_t SLen(const char *sptr)
Definition: Standard.h:74
void MemCopy(const void *lpMem1, void *lpMem2, size_t dwSize)
Definition: Standard.h:65
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.

References iSize, SAddModule(), SAddModules(), SAdvancePast(), SAdvanceSpace(), SAppend(), SAppendChar(), SCapitalize(), SCharCount(), SCharCountEx(), SCharLastPos(), SCharPos(), SClearFrontBack(), SCopy(), SCopyEnclosed(), SCopyIdentifier(), SCopySegment(), SCopySegmentEx(), SCopyUntil(), SDelete(), SEqual2(), SEqual2NoCase(), SEqualNoCase(), SEqualUntil(), SGetLine(), SGetModule(), SInsert(), SIsModule(), SLineGetCharacters(), SModuleCount(), SNewSegment(), SRemoveModule(), SRemoveModules(), SReplaceChar(), SSearch(), SSearchNoCase(), SWildcardMatchEx(), and SWordWrap().

Referenced by C4ToolsDlg::AssertValidBackTexture(), C4ToolsDlg::AssertValidTexture(), C4FindObjectAction::Check(), C4Group::Clear(), C4LandscapeRenderGL::Clear(), C4Def::Clear(), C4Network2Res::Clear(), C4ConsoleGUIPreviewWindow::Close(), CommandByName(), C4MaterialReaction::CompileFunc(), CopyDirectory(), C4ValueMapData::CreateTempNameList(), C4PlayerList::CtrlRemoveAtClient(), C4Network2Res::Derive(), C4UpdatePackage::DoGrpUpdate(), C4UpdatePackage::DoUpdate(), EraseDirectory(), C4UpdatePackage::Execute(), C4PlayerControlDefs::FinalInit(), C4GUI::ComboBox_FillCB::FindEntry(), FnParTexCol(), 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(), C4StartupPlrSelDlg::PlayerListItem::MoveFilename(), C4ValueCompiler::Name(), C4Group::Open(), C4Group::OpenAsChild(), StdStringAdapt::operator==(), C4GraphicsOverlay::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::ResetSearch(), C4Group::Save(), C4StartupOptionsDlg::SaveConfig(), C4NameList::Set(), C4MCOverlay::SetField(), C4MCPoint::SetField(), C4ToolsDlg::SetMaterial(), C4Shader::SetScriptCategories(), C4ToolsDlg::SetTexture(), C4GUI::Dialog::SetTitle(), C4ScenarioListLoader::Entry::SetTitleInGroup(), SIsModule(), C4MaterialMap::SortEnumeration(), C4MessageInput::StoreBackBuffer(), TexColSingle(), and C4LeagueSignupDialog::UserClose().

93 { return szStr1&&szStr2?!std::strcmp(szStr1,szStr2):false; }
Here is the call graph for this function:

◆ SEqual2()

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

Definition at line 198 of file Standard.cpp.

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(), SEqual(), C4Shader::SetScriptCategories(), and C4Network2RefServer::UnpackPacket().

199 {
200  if (!szStr1 || !szStr2) return false;
201  while (*szStr1 && *szStr2)
202  if (*szStr1++ != *szStr2++) return false;
203  if (*szStr2) return false; // Str1 is shorter
204  return true;
205 }
Here is the caller graph for this function:

◆ SEqual2NoCase()

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

Definition at line 220 of file Standard.cpp.

References CharCapital().

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

221 {
222  if (!szStr1 || !szStr2) return false;
223  if (iLen==0) return true;
224  while (*szStr1 && *szStr2)
225  {
226  if ( CharCapital(*szStr1++) != CharCapital(*szStr2++)) return false;
227  if (iLen>0) { iLen--; if (iLen==0) return true; }
228  }
229  if (*szStr2) return false; // Str1 is shorter
230  return true;
231 }
char CharCapital(char cChar)
Definition: Standard.h:70
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 207 of file Standard.cpp.

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(), C4ChatControl::GetDefaultControl(), 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(), C4ObjectInfo::Load(), C4DefGraphics::Load(), C4MusicSystem::Load(), C4GameResList::LoadFoldersWithLocalDefs(), C4DefGraphics::LoadMesh(), C4Game::LoadScenarioSection(), C4DefGraphics::LoadSkeleton(), C4ObjectInfoList::NameExists(), C4ChatInputDialog::OnChatInput(), C4AulDebug::OnLog(), C4Playback::Open(), C4Application::ParseCommandLine(), C4MessageInput::ProcessCommand(), C4MessageInput::ProcessInput(), C4ChatControl::ProcessInput(), C4Surface::Read(), C4Network2IRCClient::RegisterNick(), C4GroupSet::RegisterParentFolders(), C4ScriptHost::ReloadScript(), C4Group::Rename(), C4ObjectInfo::Save(), C4ScenarioSection::ScenarioLoad(), SEqual(), SetClientPrefix(), C4Game::SetScenarioFilename(), C4Startup::SetStartScreen(), C4StartupOptionsDlg::SetSubscreen(), SIsModule(), C4ChatControl::ChatSheet::NickItem::SortFunc(), C4KeyCodeEx::String2KeyShift(), C4StartupMainDlg::UpdateParticipants(), C4ChatControl::UpdateShownPage(), C4InVal::ValidateString(), and C4PlayerInfoListAttributeConflictResolver::~C4PlayerInfoListAttributeConflictResolver().

208 {
209  if (!szStr1 || !szStr2) return false;
210  if (iLen==0) return true;
211  while (*szStr1 && *szStr2)
212  {
213  if ( CharCapital(*szStr1++) != CharCapital(*szStr2++)) return false;
214  if (iLen>0) { iLen--; if (iLen==0) return true; }
215  }
216  if (*szStr1 || *szStr2) return false;
217  return true;
218 }
char CharCapital(char cChar)
Definition: Standard.h:70
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 184 of file Standard.cpp.

Referenced by SEqual().

185 {
186  if (!szStr1 || !szStr2) return false;
187  while (*szStr1 || *szStr2)
188  {
189  if ((*szStr1==cWild) || (*szStr2==cWild)) return true;
190  if (*szStr1!=*szStr2) return false;
191  szStr1++; szStr2++;
192  }
193  return true;
194 }
Here is the caller graph for this function:

◆ SGetLine()

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

Definition at line 473 of file Standard.cpp.

Referenced by C4AulParseError::C4AulParseError(), C4MCParserErr::C4MCParserErr(), C4AulScriptFunc::GetLineOfCode(), C4ScriptHost::Parse(), SEqual(), C4Shader::SetScriptCategories(), and C4ScriptHost::Warn().

474 {
475  if (!szText || !cpPosition) return 0;
476  int iLines = 1;
477  while (*szText && (szText<cpPosition))
478  {
479  if (*szText == 0x0A) iLines++;
480  szText++;
481  }
482  return iLines;
483 }
Here is the caller graph for this function:

◆ SGetModule()

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

Definition at line 533 of file Standard.cpp.

References SClearFrontBack(), and SCopySegment().

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

534 {
535  if (!szList || !sTarget) return false;
536  if (!SCopySegment(szList,iIndex,sTarget,';',iSize)) return false;
537  SClearFrontBack(sTarget);
538  return true;
539 }
bool SCopySegment(const char *szString, int iSegment, char *sTarget, char cSeparator, int iMaxL, bool fSkipWhitespace)
Definition: Standard.cpp:273
int SClearFrontBack(char *szString, char cClear)
Definition: Standard.cpp:455
int iSize
Definition: TstC4NetIO.cpp:32
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.

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

45 { return val < 0 ? -1 : val > 0 ? 1 : 0; }
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 503 of file Standard.cpp.

References MemCopy(), and SLen().

Referenced by C4Group::GetFullName(), and SEqual().

504 {
505  // Safety
506  if (!szString || !szInsert || !szInsert[0]) return;
507  size_t insertlen = strlen(szInsert);
508  if (iMaxLen >= 0 && strlen(szString) + insertlen > (size_t) iMaxLen) return;
509  // Move up string remainder
510  memmove (szString + iPosition + insertlen, szString + iPosition, SLen(szString+ iPosition) + 1);
511  // Copy insertion
512  MemCopy( szInsert, szString+iPosition, SLen(szInsert) );
513 }
size_t SLen(const char *sptr)
Definition: Standard.h:74
void MemCopy(const void *lpMem1, void *lpMem2, size_t dwSize)
Definition: Standard.h:65
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 541 of file Standard.cpp.

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

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

542 {
543  char szModule[1024+1];
544  // Compare all modules
545  for (int iMod=0; SGetModule(szList,iMod,szModule,1024); iMod++)
546  if (fCaseSensitive ? SEqual(szString,szModule) : SEqualNoCase(szString,szModule))
547  {
548  // Provide index if desired
549  if (ipIndex) *ipIndex = iMod;
550  // Found
551  return true;
552  }
553  // Not found
554  return false;
555 }
bool SGetModule(const char *szList, int iIndex, char *sTarget, int iSize)
Definition: Standard.cpp:533
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:207
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:93
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.

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(), C4Group::GetFullName(), C4Language::GetPackGroups(), GetRelativePathS(), GetTrailingNumber(), C4GUI::Edit::InsertText(), C4GUI::IsWholeWordSpacer(), C4Language::LoadComponentHost(), C4MaterialMap::LoadEnumeration(), C4TextureMap::LoadTextures(), LogSilent(), MakeFilenameFromTitle(), C4ObjectInfoList::MakeValidName(), C4Player::Message(), C4ChatInputDialog::OnChatInput(), C4GUI::Edit::OnContext(), C4GUI::Edit::OnGetFocus(), C4Group::Open(), C4Group::OpenAsChild(), C4Application::ParseCommandLine(), C4Console::PlayerJoin(), C4MessageInput::ProcessInput(), C4Network2HTTPClient::Query(), C4Game::QuickSave(), C4Markup::Read(), RealPath(), C4Network2IRCClient::RegisterNick(), C4GroupSet::RegisterParentFolders(), C4LangStringTable::ReplaceStrings(), C4ValueMapNames::Reset(), SAppend(), C4ObjectInfo::Save(), C4MaterialMap::SaveEnumeration(), SClearFrontBack(), SDelete(), C4GUI::Edit::SelectAll(), C4Network2Res::SetByCore(), SetClientPrefix(), C4Application::SetGameFont(), C4StartupOptionsDlg::SetSubscreen(), C4MusicFileSDL::SetVolume(), SInsert(), SRemoveModule(), SSearch(), SSearchNoCase(), C4Record::Start(), TruncateBackslash(), C4LeagueSignupDialog::UserClose(), and CStdFile::WriteString().

74 { return sptr?std::strlen(sptr):0; }
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.

References GetNextUTF8Character().

76 {
77  if (!szStr) return 0;
78  const char *end = std::strchr(szStr, cUntil);
79  return end ? end-szStr : std::strlen(szStr);
80 }
Here is the call graph for this function:

◆ SLineGetCharacters()

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

Definition at line 485 of file Standard.cpp.

Referenced by C4AulParseError::C4AulParseError(), SEqual(), and C4ScriptHost::Warn().

486 {
487  if (!szText || !cpPosition) return 0;
488  int iChars = 1;
489  while (*szText && (szText<cpPosition))
490  {
491  if (*szText == 0x0A)
492  iChars = 1;
493  else if (*szText == '\t')
494  // assume a tab stop every 8 characters
495  iChars = ((iChars - 1 + 8) & ~7) + 1;
496  else
497  iChars++;
498  szText++;
499  }
500  return iChars;
501 }
Here is the caller graph for this function:

◆ SModuleCount()

int SModuleCount ( const char *  szList)

Definition at line 611 of file Standard.cpp.

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

612 {
613  if (!szList) return 0;
614  int iCount = 0;
615  bool fNewModule = true;
616  while (*szList)
617  {
618  switch (*szList)
619  {
620  case ' ': break;
621  case ';': fNewModule=true; break;
622  default: if (fNewModule) iCount++; fNewModule=false; break;
623  }
624  szList++;
625  }
626  return iCount;
627 }
Here is the caller graph for this function:

◆ SNewSegment()

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

Definition at line 468 of file Standard.cpp.

References SAppend().

Referenced by SAddModule(), and SEqual().

469 {
470  if (szStr[0]) SAppend(szSepa,szStr);
471 }
void SAppend(const char *szSource, char *szTarget, int iMaxL)
Definition: Standard.cpp:257
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 582 of file Standard.cpp.

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

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

583 {
584  int iMod,iPos,iLen;
585  // Not a module
586  if (!SIsModule(szList,szModule,&iMod,fCaseSensitive)) return false;
587  // Get module start
588  iPos = 0;
589  if (iMod > 0) iPos = SCharPos(';',szList,iMod-1)+1;
590  // Get module length
591  iLen = SCharPos(';',szList+iPos);
592  if (iLen<0) iLen=SLen(szList); else iLen+=1;
593  // Delete module
594  SDelete(szList,iLen,iPos);
595  // Success
596  return true;
597 }
bool SIsModule(const char *szList, const char *szString, int *ipIndex, bool fCaseSensitive)
Definition: Standard.cpp:541
size_t SLen(const char *sptr)
Definition: Standard.h:74
void SDelete(char *szString, int iLen, int iPosition)
Definition: Standard.cpp:515
int SCharPos(char cTarget, const char *szInStr, int iIndex)
Definition: Standard.cpp:233
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 599 of file Standard.cpp.

References SGetModule(), and SRemoveModule().

Referenced by C4StartupScenSelDlg::KeyCheat2(), and SEqual().

600 {
601  // Safety / no empties
602  if (!szList || !szModules || !szModules[0]) return false;
603  // Remove modules
604  char szModule[1024+1]; // limited
605  for (int cnt=0; SGetModule(szModules,cnt,szModule,1024); cnt++)
606  SRemoveModule(szList,szModule,fCaseSensitive);
607  // Success
608  return true;
609 }
bool SGetModule(const char *szList, int iIndex, char *sTarget, int iSize)
Definition: Standard.cpp:533
bool SRemoveModule(char *szList, const char *szModule, bool fCaseSensitive)
Definition: Standard.cpp:582
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 348 of file Standard.cpp.

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

349 {
350  while (str && *str)
351  { if (*str==fc) *str=tc; str++; }
352 }
Here is the caller graph for this function:

◆ SSearch()

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

Definition at line 363 of file Standard.cpp.

References SLen().

Referenced by C4ClientPlayerInfos::C4ClientPlayerInfos(), C4DownloadDlg::DownloadFile(), C4Config::ExpandEnvironmentVariables(), C4TextureMap::GetIndexMatTex(), C4ComponentHost::GetLanguageString(), GetTextColorForBackground(), C4Network2IRCChannel::getUser(), C4ComponentHost::Load(), C4MusicSystem::LoadDir(), C4MaterialMap::LoadEnumeration(), C4TextureMap::LoadFlags(), C4Player::LoadRuntimeData(), LogFatal(), C4MessageInput::ProcessCommand(), C4Network2IRCClient::RegisterNick(), StdStrBuf::Replace(), C4LangStringTable::ReplaceStrings(), SEqual(), C4StartupOptionsDlg::SetSubscreen(), C4Landscape::SetTextureIndex(), C4Markup::StripMarkup(), C4Network2HTTPClient::UnpackPacket(), and C4Network2IRCClient::~C4Network2IRCClient().

364 {
365  const char *cscr;
366  size_t indexlen,match=0;
367  if (!szString || !szIndex) return nullptr;
368  indexlen=SLen(szIndex);
369  for (cscr=szString; cscr && *cscr; cscr++)
370  {
371  if (*cscr==szIndex[match]) match++;
372  else match=0;
373  if (match>=indexlen) return cscr+1;
374  }
375  return nullptr;
376 }
size_t SLen(const char *sptr)
Definition: Standard.h:74
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 378 of file Standard.cpp.

References CharCapital(), and SLen().

Referenced by C4StartupNetListEntry::KeywordMatch(), and SEqual().

379 {
380  const char *cscr;
381  size_t indexlen,match=0;
382  if (!szString || !szIndex) return nullptr;
383  indexlen=SLen(szIndex);
384  for (cscr=szString; cscr && *cscr; cscr++)
385  {
386  if (CharCapital(*cscr)==CharCapital(szIndex[match])) match++;
387  else match=0;
388  if (match>=indexlen) return cscr+1;
389  }
390  return nullptr;
391 }
size_t SLen(const char *sptr)
Definition: Standard.h:74
char CharCapital(char cChar)
Definition: Standard.h:70
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 167 of file Standard.h.

References GNUC_FORMAT_ATTRIBUTE, IsValidUtf8(), strprintf(), and vstrprintf().

168 {
169  va_list args; va_start(args, fmt);
170  int m = vsnprintf(str, N, fmt, args);
171  // Quick exit if vsnprintf failed
172  if (m < 0) return m;
173  if (static_cast<size_t>(m) >= N) { m = N-1; str[m] = 0; }
174  return m;
175 }
Here is the call graph for this function:

◆ strprintf()

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

Definition at line 832 of file Standard.cpp.

References s, and vstrprintf().

Referenced by C4GUI::MessageDialog::MessageDialog(), and ssprintf().

833 {
834  va_list args;
835  va_start(args, format);
836  std::string s = vstrprintf(format, args);
837  va_end(args);
838  return s;
839 }
std::string vstrprintf(const char *format, va_list args)
Definition: Standard.cpp:816
#define s
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.

References s.

Referenced by DWordAligned().

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 }
#define s
Here is the caller graph for this function:

◆ SWildcardMatchEx()

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

Definition at line 629 of file Standard.cpp.

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

630 {
631  // safety
632  if (!szString || !szWildcard) return false;
633  // match char-wise
634  const char *pWild = szWildcard, *pPos = szString;
635  const char *pLWild = nullptr, *pLPos = nullptr; // backtracking
636  while (*pWild || pLWild)
637  // string wildcard?
638  if (*pWild == '*')
639  { pLWild = ++pWild; pLPos = pPos; }
640  // nothing left to match?
641  else if (!*pPos)
642  break;
643  // equal or one-character-wildcard? proceed
644  else if (*pWild == '?' || *pWild == *pPos)
645  { pWild++; pPos++; }
646  // backtrack possible?
647  else if (pLPos)
648  { pWild = pLWild; pPos = ++pLPos; }
649  // match failed
650  else
651  return false;
652  // match complete if both strings are fully matched
653  return !*pWild && !*pPos;
654 }
Here is the caller graph for this function:

◆ SWordWrap()

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

Definition at line 393 of file Standard.cpp.

Referenced by C4Game::DrawCrewOverheadText(), and SEqual().

394 {
395  if (!szText) return;
396  // Scan string
397  char *cPos,*cpLastSpace=nullptr;
398  int iLineRun=0;
399  for (cPos=szText; *cPos; cPos++)
400  {
401  // Store last space
402  if (*cPos==cSpace) cpLastSpace=cPos;
403  // Separator encountered: reset line run
404  if (*cPos==cSepa) iLineRun=0;
405  // Need a break, insert at last space
406  if (iLineRun>=iMaxLine)
407  if (cpLastSpace)
408  { *cpLastSpace=cSepa; iLineRun=cPos - cpLastSpace; }
409  // Line run
410  iLineRun++;
411  }
412 }
Here is the caller graph for this function:

◆ vstrprintf()

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

Definition at line 816 of file Standard.cpp.

References s.

Referenced by ssprintf(), and strprintf().

817 {
818  va_list argcopy;
819  va_copy(argcopy, args);
820  int size = vsnprintf(nullptr, 0, format, argcopy);
821  if (size < 0)
822  throw std::invalid_argument("invalid argument to strprintf");
823  va_end(argcopy);
824  std::string s;
825  s.resize(size + 1);
826  size = vsnprintf(&s[0], s.size(), format, args);
827  assert(size >= 0);
828  s.resize(size);
829  return s;
830 }
#define s
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