OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
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)
 
int Angle (int iX1, int iY1, int iX2, int iY2)
 
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

Function Documentation

int Angle ( int  iX1,
int  iY1,
int  iX2,
int  iY2 
)

Definition at line 36 of file Standard.cpp.

References Abs().

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

37 {
38  int iAngle = (int) ( 180.0 * atan2( float(Abs(iY1-iY2)), float(Abs(iX1-iX2)) ) / M_PI );
39  if (iX2>iX1 )
40  { if (iY2<iY1) iAngle = 90-iAngle; else iAngle = 90+iAngle; }
41  else
42  { if (iY2<iY1) iAngle = 270+iAngle; else iAngle = 270-iAngle; }
43  return iAngle;
44 }
T Abs(T val)
Definition: Standard.h:42

Here is the call graph for this function:

Here is the caller graph for this function:

char CharCapital ( char  cChar)
inline

Definition at line 70 of file Standard.h.

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

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

Here is the caller graph for this function:

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(), 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:

int DWordAligned ( int  val)
inline

Definition at line 47 of file Standard.h.

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 caller graph for this function:

int GetCharacterCount ( const char *  s)

Definition at line 763 of file Standard.cpp.

References s.

764 {
765  int l = 0;
766  while (*s)
767  {
768  unsigned char c = *s;
769  if (c < 128 || c > 247)
770  {
771  ++l;
772  s += 1;
773  }
774  else if (c > 191 && c < 224)
775  {
776  ++l;
777  s += 2;
778  }
779  else if (c >= 224 && c <= 239)
780  {
781  ++l;
782  s += 3;
783  }
784  else if (c >= 240 && c <= 247)
785  {
786  ++l;
787  s += 4;
788  }
789  else assert(false);
790  }
791  return l;
792 }
#define s
uint32_t GetNextCharacter ( const char **  pszString)
inline

Definition at line 84 of file Standard.h.

References GetNextUTF8Character().

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:727

Here is the call graph for this function:

Here is the caller graph for this function:

uint32_t GetNextUTF8Character ( const char **  pszString)

Definition at line 727 of file Standard.cpp.

Referenced by GetNextCharacter().

728 {
729  // assume the current character is UTF8 already (i.e., highest bit set)
730  const uint32_t REPLACEMENT_CHARACTER = 0xFFFDu;
731  const char *szString = *pszString;
732  unsigned char c = *szString++;
733  uint32_t dwResult = REPLACEMENT_CHARACTER;
734  assert(c>127);
735  if (c>191 && c<224)
736  {
737  unsigned char c2 = *szString++;
738  if ((c2 & 192) != 128) { *pszString = szString; return REPLACEMENT_CHARACTER; }
739  dwResult = (int(c&31)<<6) | (c2&63); // two char code
740  }
741  else if (c >= 224 && c <= 239)
742  {
743  unsigned char c2 = *szString++;
744  if ((c2 & 192) != 128) { *pszString = szString; return REPLACEMENT_CHARACTER; }
745  unsigned char c3 = *szString++;
746  if ((c3 & 192) != 128) { *pszString = szString; return REPLACEMENT_CHARACTER; }
747  dwResult = (int(c&15)<<12) | (int(c2&63)<<6) | int(c3&63); // three char code
748  }
749  else if (c >= 240 && c <= 247)
750  {
751  unsigned char c2 = *szString++;
752  if ((c2 & 192) != 128) { *pszString = szString; return REPLACEMENT_CHARACTER; }
753  unsigned char c3 = *szString++;
754  if ((c3 & 192) != 128) { *pszString = szString; return REPLACEMENT_CHARACTER; }
755  unsigned char c4 = *szString++;
756  if ((c4 & 192) != 128) { *pszString = szString; return REPLACEMENT_CHARACTER; }
757  dwResult = (int(c&7)<<18) | (int(c2&63)<<12) | (int(c3&63)<<6) | int(c4&63); // four char code
758  }
759  *pszString = szString;
760  return dwResult;
761 }

Here is the caller graph for this function:

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

bool IsIdentifier ( char  cChar)

Definition at line 68 of file Standard.cpp.

References Inside().

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

69 {
70  if (Inside(cChar,'A','Z')) return true;
71  if (Inside(cChar,'a','z')) return true;
72  if (Inside(cChar,'0','9')) return true;
73  if (cChar=='_') return true;
74  if (cChar=='~') return true;
75  if (cChar=='+') return true;
76  if (cChar=='-') return true;
77  return false;
78 }
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:

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

Definition at line 674 of file Standard.cpp.

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

675 {
676  // Intentionally using a C-style cast to always get a uint8_t* from char*;
677  // reinterpret_cast would fail here on platforms that have unsigned char,
678  // while static_cast would fail on platforms with a signed char type
679  const uint8_t *input = (const uint8_t*)(text);
680 
681  for (const uint8_t *cursor = input; length < 0 ? *cursor != 0 : cursor - input < length; ++cursor)
682  {
683  int continuation_bytes = utf8_continuation_byte_table[*cursor];
684  if (continuation_bytes < 0)
685  return false;
686  else if (continuation_bytes == 0)
687  {
688  // Standard 7-bit ASCII value (i.e., 1 byte codepoint)
689  continue;
690  }
691  else if (length >= 0 && cursor - input + continuation_bytes >= length)
692  {
693  // Too few remaining bytes
694  return false;
695  }
696 
697  // Compute character value, so we can detect overlong sequences
698  assert((*cursor & 0xC0) == 0xC0);
699  uint32_t value = *cursor;
700  // strip length bits off the start byte
701  value &= (0xFF >> (continuation_bytes + 1));
702  for (int byte = 0; byte < continuation_bytes; ++byte)
703  {
704  // check that this is actually a continuation byte
705  if ((cursor[byte + 1] & 0xC0) != 0x80)
706  return false;
707  // merge continuation byte into value
708  value <<= 6;
709  value |= cursor[byte + 1] & 0x3F;
710  }
711  // make sure this is not overlong
712  if (value < utf8_min_char_value[continuation_bytes])
713  return false;
714  // and also not beyond 0x10FFFF
715  if (value > 0x10FFFF)
716  return false;
717  // and also not a wrongly encoded UTF-16 surrogate half
718  if (value >= 0xD800 && value <= 0xDFFF)
719  return false;
720  cursor += continuation_bytes;
721  }
722  // Looks fine
723  return true;
724 }

Here is the caller graph for this function:

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:

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:

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:

int Pow ( int  base,
int  exponent 
)

Definition at line 47 of file Standard.cpp.

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

48 {
49  if (exponent < 0) return 0;
50 
51  int result = 1;
52 
53  if (exponent & 1) result = base;
54  exponent >>= 1;
55 
56  while (exponent)
57  {
58  base *= base;
59  if (exponent & 1) result *= base;
60  exponent >>= 1;
61  }
62 
63  return result;
64 }

Here is the caller graph for this function:

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

Definition at line 535 of file Standard.cpp.

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

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

536 {
537  // Safety / no empties
538  if (!szList || !szModule || !szModule[0]) return false;
539  // Already a module?
540  if (SIsModule(szList,szModule,nullptr,fCaseSensitive)) return false;
541  // New segment, add string
542  SNewSegment(szList);
543  SAppend(szModule,szList);
544  // Success
545  return true;
546 }
void SAppend(const char *szSource, char *szTarget, int iMaxL)
Definition: Standard.cpp:235
bool SIsModule(const char *szList, const char *szString, int *ipIndex, bool fCaseSensitive)
Definition: Standard.cpp:519
void SNewSegment(char *szStr, const char *szSepa)
Definition: Standard.cpp:446

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 548 of file Standard.cpp.

References SAddModule(), and SGetModule().

Referenced by C4StartupScenSelDlg::KeyCheat2().

549 {
550  // Safety / no empties
551  if (!szList || !szModules || !szModules[0]) return false;
552  // Add modules
553  char szModule[1024+1]; // limited
554  for (int cnt=0; SGetModule(szModules,cnt,szModule,1024); cnt++)
555  SAddModule(szList,szModule,fCaseSensitive);
556  // Success
557  return true;
558 }
bool SGetModule(const char *szList, int iIndex, char *sTarget, int iSize)
Definition: Standard.cpp:511
bool SAddModule(char *szList, const char *szModule, bool fCaseSensitive)
Definition: Standard.cpp:535

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 410 of file Standard.cpp.

Referenced by C4GameMessage::Append().

411 {
412  if (!szSPos) return nullptr;
413  while (*szSPos)
414  {
415  if (*szSPos==cPast) { szSPos++; break; }
416  szSPos++;
417  }
418  return szSPos;
419 }

Here is the caller graph for this function:

const char* SAdvanceSpace ( const char *  szSPos)

Definition at line 392 of file Standard.cpp.

References IsWhiteSpace().

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

393 {
394  if (!szSPos) return nullptr;
395  while (IsWhiteSpace(*szSPos)) szSPos++;
396  return szSPos;
397 }
bool IsWhiteSpace(char cChar)
Definition: Standard.h:72

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 235 of file Standard.cpp.

References SCopy(), and SLen().

Referenced by C4Config::AtExePath(), C4Config::AtNetworkPath(), C4Config::AtScreenshotPath(), C4Config::AtSystemDataPath(), C4Config::AtTempPath(), C4Config::AtTempUpdatePath(), C4Config::AtUserDataPath(), 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(), C4UpdatePackage::MkUp(), RealPath(), C4Group::Rename(), C4ScenarioListLoader::Entry::RenameTo(), SAddModule(), C4ObjectInfo::Save(), C4Group::Save(), C4MaterialMap::SaveEnumeration(), C4Surface::SavePNG(), SetClientPrefix(), SNewSegment(), C4Playback::StreamToRecord(), and C4ObjectList::Write().

236 {
237  if (iMaxL == -1)
238  SCopy(szSource, szTarget + SLen(szTarget));
239  else
240  SCopy(szSource, szTarget + SLen(szTarget), iMaxL - SLen(szTarget));
241 }
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:130
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:

void SAppendChar ( char  cChar,
char *  szStr 
)

Definition at line 243 of file Standard.cpp.

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

244 {
245  if (!szStr) return;
246  char *cPos;
247  for (cPos=szStr; *cPos; cPos++) {}
248  *cPos=cChar; *(cPos+1)=0;
249 }

Here is the caller graph for this function:

void SCapitalize ( char *  szString)

Definition at line 332 of file Standard.cpp.

References CharCapital().

Referenced by C4ChatInputDialog::OnChatInput().

333 {
334  while (str && *str)
335  {
336  *str=CharCapital(*str);
337  str++;
338  }
339 }
char CharCapital(char cChar)
Definition: Standard.h:70

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 298 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(), and SortRank().

299 {
300  unsigned int iResult=0;
301  // Scan string
302  while (*szInStr)
303  {
304  // End position reached (end character is not included)
305  if (szInStr==cpUntil) return iResult;
306  // Character found
307  if (*szInStr==cTarget) iResult++;
308  // Advance
309  szInStr++;
310  }
311  // Done
312  return iResult;
313 }
int iResult
Definition: C4GroupMain.cpp:39

Here is the caller graph for this function:

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

Definition at line 315 of file Standard.cpp.

References iResult, and SCharCount().

Referenced by C4LeagueSignupDialog::UserClose().

316 {
317  unsigned int iResult = 0;
318  while ( *szCharList )
319  {
320  iResult += SCharCount( *szCharList, szString );
321  szCharList++;
322  }
323  return iResult;
324 }
unsigned int SCharCount(char cTarget, const char *szInStr, const char *cpUntil)
Definition: Standard.cpp:298
int iResult
Definition: C4GroupMain.cpp:39

Here is the call graph for this function:

Here is the caller graph for this function:

int SCharLastPos ( char  cTarget,
const char *  szInStr 
)

Definition at line 225 of file Standard.cpp.

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

226 {
227  const char *cpos;
228  int ccpos,lcpos;
229  if (!szInStr) return -1;
230  for (cpos=szInStr,ccpos=0,lcpos=-1; *cpos; cpos++,ccpos++)
231  if (*cpos==cTarget) lcpos=ccpos;
232  return lcpos;
233 }

Here is the caller graph for this function:

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

Definition at line 211 of file Standard.cpp.

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

212 {
213  const char *cpos;
214  int ccpos;
215  if (!szInStr) return -1;
216  for (cpos=szInStr,ccpos=0; *cpos; cpos++,ccpos++)
217  if (*cpos==cTarget)
218  {
219  if (iIndex==0) return ccpos;
220  else iIndex--;
221  }
222  return -1;
223 }

Here is the caller graph for this function:

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

Definition at line 433 of file Standard.cpp.

References SLen().

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

434 {
435  int cleared=0;
436  char *cpos;
437  if (!szString) return 0;
438  for (cpos=szString; *cpos && (*cpos==cClear); cpos++,cleared++) {}
439  // strcpy is undefined when used on overlapping strings...
440  if (cpos!=szString) memmove(szString, cpos, SLen(cpos) + 1);
441  for (cpos=szString+SLen(szString)-1; (cpos>szString) && (*cpos==cClear); cpos--,cleared++)
442  *cpos=0x00;
443  return cleared;
444 }
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:

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

Definition at line 139 of file Standard.cpp.

140 {
141  if (szSource == sTarget) return;
142  if (!sTarget) return; *sTarget=0; if (!szSource) return;
143  strcpy(sTarget,szSource);
144 }
void SCopy ( const char *  szSource,
char *  sTarget,
size_t  iMaxL 
)

Definition at line 130 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(), CopyDirectory(), CStdFile::Create(), C4Network2ResList::CreateNetworkFolder(), C4ConfigGeneral::CreateSaveFolder(), C4TeamList::CreateTeam(), C4ObjectInfoCore::Default(), C4ToolsDlg::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(), FnStringFormat(), ForEachFile(), C4GUI::Edit::GetCurrentWord(), C4SoundSystem::GetEffect(), GetFilenameOnly(), C4Language::GetPackGroups(), GetParentPath(), C4Network2Res::GetStandalone(), CStdFont::GetTextExtent(), C4LoaderScreen::Init(), C4MusicFile::Init(), C4RankSystem::Init(), CStdFont::Init(), C4Game::Init(), C4Player::Init(), C4Network2::Join(), C4SoundEffect::Load(), C4ObjectInfo::Load(), C4FacetSurface::Load(), C4DefGraphics::Load(), C4StartupPlrSelDlg::PlayerListItem::Load(), C4Surface::Load(), C4Player::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(), 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(), SAppend(), C4ObjectInfo::Save(), C4Group::Save(), C4Player::Save(), C4Landscape::P::SaveInternal(), C4Surface::SavePNG(), C4Console::SaveScenario(), SCopyEnclosed(), C4LoaderScreen::SeekLoaderScreens(), 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(), C4GUI::ComboBox::SetText(), C4ToolsDlg::SetTexture(), C4Record::Start(), C4StartupScenSelDlg::StartScenario(), C4MessageInput::StoreBackBuffer(), C4Playback::StreamToRecord(), StdCompilerINIRead::String(), and C4InVal::ValidateString().

131 {
132  if (szSource == sTarget) return;
133  if (!sTarget) return; *sTarget=0; if (!szSource) return;
134  while (*szSource && (iMaxL>0))
135  { *sTarget=*szSource; iMaxL--; szSource++; sTarget++; }
136  *sTarget=0;
137 }
bool SCopyEnclosed ( const char *  szSource,
char  cOpen,
char  cClose,
char *  sTarget,
int  iSize 
)

Definition at line 501 of file Standard.cpp.

References SCharPos(), and SCopy().

Referenced by C4Markup::Read().

502 {
503  int iPos,iLen;
504  if (!szSource || !sTarget) return false;
505  if ((iPos = SCharPos(cOpen,szSource)) < 0) return false;
506  if ((iLen = SCharPos(cClose,szSource+iPos+1)) < 0) return false;
507  SCopy(szSource+iPos+1,sTarget,std::min(iLen,iSize));
508  return true;
509 }
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:130
int SCharPos(char cTarget, const char *szInStr, int iIndex)
Definition: Standard.cpp:211
int iSize
Definition: TstC4NetIO.cpp:32

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 421 of file Standard.cpp.

References IsIdentifier().

Referenced by C4MaterialMap::LoadEnumeration().

422 {
423  if (!szSource || !sTarget) return;
424  while (IsIdentifier(*szSource))
425  {
426  if (iMaxL==1) { *sTarget++ = *szSource++; break; }
427  iMaxL--;
428  *sTarget++ = *szSource++;
429  }
430  *sTarget=0;
431 }
bool IsIdentifier(char cChar)
Definition: Standard.cpp:68

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 251 of file Standard.cpp.

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(), C4ComponentHost::Load(), C4GameResList::Load(), C4SoundSystem::LoadEffects(), C4Language::LoadLanguage(), C4MainMenu::MenuCommand(), C4Group::Merge(), C4StartupMainDlg::OnPlayerSelContextRemove(), C4StartupMainDlg::OnPlayerSelContextRemovePlr(), RegisterShellExtensions(), SGetModule(), SortRank(), UnregisterShellExtensions(), and C4StartupMainDlg::UpdateParticipants().

253 {
254  // Advance to indexed segment
255  while (iSegment>0)
256  {
257  if (SCharPos(cSeparator,szString) == -1)
258  { sTarget[0]=0; return false; }
259  szString += SCharPos(cSeparator,szString)+1;
260  iSegment--;
261  }
262  // Advance whitespace
263  if (fSkipWhitespace)
264  szString = SAdvanceSpace(szString);
265  // Copy segment contents
266  SCopyUntil(szString,sTarget,cSeparator,iMaxL);
267  return true;
268 }
const char * SAdvanceSpace(const char *szSPos)
Definition: Standard.cpp:392
int SCharPos(char cTarget, const char *szInStr, int iIndex)
Definition: Standard.cpp:211
void SCopyUntil(const char *szSource, char *sTarget, char cUntil, int iMaxL, int iIndex)
Definition: Standard.cpp:146

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 270 of file Standard.cpp.

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

Referenced by C4Draw::TextOut().

272 {
273  // Advance to indexed segment
274  while (iSegment>0)
275  {
276  // use the separator that's closer
277  int iPos1 = SCharPos(cSep1,szString), iPos2 = SCharPos(cSep2,szString);
278  if (iPos1 == -1)
279  if (iPos2 == -1)
280  { sTarget[0]=0; return false; }
281  else
282  iPos1=iPos2;
283  else if (iPos2 != -1 && iPos2 < iPos1)
284  iPos1 = iPos2;
285  szString += iPos1+1;
286  iSegment--;
287  }
288  // Advance whitespace
289  if (fSkipWhitespace)
290  szString = SAdvanceSpace(szString);
291  // Copy segment contents; use separator that's closer
292  int iPos1 = SCharPos(cSep1,szString), iPos2 = SCharPos(cSep2,szString);
293  if (iPos2 != -1 && (iPos2 < iPos1 || iPos1 == -1)) cSep1 = cSep2;
294  SCopyUntil(szString,sTarget,cSep1,iMaxL);
295  return true;
296 }
const char * SAdvanceSpace(const char *szSPos)
Definition: Standard.cpp:392
int SCharPos(char cTarget, const char *szInStr, int iIndex)
Definition: Standard.cpp:211
void SCopyUntil(const char *szSource, char *sTarget, char cUntil, int iMaxL, int iIndex)
Definition: Standard.cpp:146

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 146 of file Standard.cpp.

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

147 {
148  if (szSource == sTarget) return;
149  if (!sTarget) return; *sTarget=0; if (!szSource) return;
150  while ( *szSource && ((*szSource!=cUntil) || (iIndex>0)) && (iMaxL!=0) )
151  { *sTarget=*szSource; if (*szSource==cUntil) iIndex--; szSource++; sTarget++; iMaxL--; }
152  *sTarget=0;
153 }

Here is the caller graph for this function:

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

Definition at line 155 of file Standard.cpp.

156 {
157  size_t n = std::min(strcspn(szSource, sUntil), iMaxL - 1);
158  strncpy(sTarget, szSource, n);
159  sTarget[n] = 0;
160 }
void SDelete ( char *  szString,
int  iLen,
int  iPosition = 0 
)

Definition at line 493 of file Standard.cpp.

References MemCopy(), and SLen().

Referenced by SRemoveModule().

494 {
495  // Safety
496  if (!szString) return;
497  // Move down string remainder
498  MemCopy( szString+iPosition+iLen, szString+iPosition, SLen(szString+iPosition+iLen)+1 );
499 }
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:

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

Definition at line 93 of file Standard.h.

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(), 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(), 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::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().

93 { return szStr1&&szStr2?!std::strcmp(szStr1,szStr2):false; }
bool SEqual2 ( const char *  szStr1,
const char *  szStr2 
)

Definition at line 176 of file Standard.cpp.

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

177 {
178  if (!szStr1 || !szStr2) return false;
179  while (*szStr1 && *szStr2)
180  if (*szStr1++ != *szStr2++) return false;
181  if (*szStr2) return false; // Str1 is shorter
182  return true;
183 }

Here is the caller graph for this function:

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

Definition at line 198 of file Standard.cpp.

References CharCapital().

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

199 {
200  if (!szStr1 || !szStr2) return false;
201  if (iLen==0) return true;
202  while (*szStr1 && *szStr2)
203  {
204  if ( CharCapital(*szStr1++) != CharCapital(*szStr2++)) return false;
205  if (iLen>0) { iLen--; if (iLen==0) return true; }
206  }
207  if (*szStr2) return false; // Str1 is shorter
208  return true;
209 }
char CharCapital(char cChar)
Definition: Standard.h:70

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 185 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(), 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(), C4Playback::Open(), C4Application::ParseCommandLine(), C4MessageInput::ProcessCommand(), C4MessageInput::ProcessInput(), C4ChatControl::ProcessInput(), C4Surface::Read(), C4GroupSet::RegisterParentFolders(), C4ScriptHost::ReloadScript(), C4Group::Rename(), C4ObjectInfo::Save(), C4ScenarioSection::ScenarioLoad(), SetClientPrefix(), C4Game::SetScenarioFilename(), C4Startup::SetStartScreen(), C4StartupOptionsDlg::SetSubscreen(), SIsModule(), C4KeyCodeEx::String2KeyCode(), C4KeyCodeEx::String2KeyShift(), C4StartupMainDlg::UpdateParticipants(), and C4InVal::ValidateString().

186 {
187  if (!szStr1 || !szStr2) return false;
188  if (iLen==0) return true;
189  while (*szStr1 && *szStr2)
190  {
191  if ( CharCapital(*szStr1++) != CharCapital(*szStr2++)) return false;
192  if (iLen>0) { iLen--; if (iLen==0) return true; }
193  }
194  if (*szStr1 || *szStr2) return false;
195  return true;
196 }
char CharCapital(char cChar)
Definition: Standard.h:70

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 162 of file Standard.cpp.

163 {
164  if (!szStr1 || !szStr2) return false;
165  while (*szStr1 || *szStr2)
166  {
167  if ((*szStr1==cWild) || (*szStr2==cWild)) return true;
168  if (*szStr1!=*szStr2) return false;
169  szStr1++; szStr2++;
170  }
171  return true;
172 }
int SGetLine ( const char *  szText,
const char *  cpPosition 
)

Definition at line 451 of file Standard.cpp.

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

452 {
453  if (!szText || !cpPosition) return 0;
454  int iLines = 1;
455  while (*szText && (szText<cpPosition))
456  {
457  if (*szText == 0x0A) iLines++;
458  szText++;
459  }
460  return iLines;
461 }

Here is the caller graph for this function:

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

Definition at line 511 of file Standard.cpp.

References SClearFrontBack(), and SCopySegment().

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

512 {
513  if (!szList || !sTarget) return false;
514  if (!SCopySegment(szList,iIndex,sTarget,';',iSize)) return false;
515  SClearFrontBack(sTarget);
516  return true;
517 }
bool SCopySegment(const char *szString, int iSegment, char *sTarget, char cSeparator, int iMaxL, bool fSkipWhitespace)
Definition: Standard.cpp:251
int SClearFrontBack(char *szString, char cClear)
Definition: Standard.cpp:433
int iSize
Definition: TstC4NetIO.cpp:32

Here is the call graph for this function:

Here is the caller graph for this function:

template<class T >
int Sign ( val)
inline

Definition at line 45 of file Standard.h.

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

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

Here is the caller graph for this function:

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

Definition at line 481 of file Standard.cpp.

References MemCopy(), and SLen().

Referenced by C4Group::GetFullName().

482 {
483  // Safety
484  if (!szString || !szInsert || !szInsert[0]) return;
485  size_t insertlen = strlen(szInsert);
486  if (iMaxLen >= 0 && strlen(szString) + insertlen > (size_t) iMaxLen) return;
487  // Move up string remainder
488  memmove (szString + iPosition + insertlen, szString + iPosition, SLen(szString+ iPosition) + 1);
489  // Copy insertion
490  MemCopy( szInsert, szString+iPosition, SLen(szInsert) );
491 }
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:

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

Definition at line 519 of file Standard.cpp.

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

520 {
521  char szModule[1024+1];
522  // Compare all modules
523  for (int iMod=0; SGetModule(szList,iMod,szModule,1024); iMod++)
524  if (fCaseSensitive ? SEqual(szString,szModule) : SEqualNoCase(szString,szModule))
525  {
526  // Provide index if desired
527  if (ipIndex) *ipIndex = iMod;
528  // Found
529  return true;
530  }
531  // Not found
532  return false;
533 }
bool SGetModule(const char *szList, int iIndex, char *sTarget, int iSize)
Definition: Standard.cpp:511
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:185
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:

size_t SLen ( const char *  sptr)
inline

Definition at line 74 of file Standard.h.

Referenced by C4MainMenu::ActivateSavegame(), C4GameMessage::Append(), AppendBackslash(), C4Config::AtScreenshotPath(), C4Group_CopyItem(), C4Group_MoveItem(), C4RankSystem::Check(), C4ConfigGeneral::DeterminePaths(), DirectoryExists(), C4GUI::Edit::DrawElement(), C4Config::ExpandEnvironmentVariables(), C4Console::FileOpenWPlrs(), C4GraphicsSystem::FlashMessage(), FnStringFormat(), 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(), C4Network2HTTPClient::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().

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

Here is the caller graph for this function:

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 }
int SLineGetCharacters ( const char *  szText,
const char *  cpPosition 
)

Definition at line 463 of file Standard.cpp.

Referenced by C4AulParseError::C4AulParseError().

464 {
465  if (!szText || !cpPosition) return 0;
466  int iChars = 1;
467  while (*szText && (szText<cpPosition))
468  {
469  if (*szText == 0x0A)
470  iChars = 1;
471  else if (*szText == '\t')
472  // assume a tab stop every 8 characters
473  iChars = ((iChars - 1 + 8) & ~7) + 1;
474  else
475  iChars++;
476  szText++;
477  }
478  return iChars;
479 }

Here is the caller graph for this function:

int SModuleCount ( const char *  szList)

Definition at line 589 of file Standard.cpp.

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

590 {
591  if (!szList) return 0;
592  int iCount = 0;
593  bool fNewModule = true;
594  while (*szList)
595  {
596  switch (*szList)
597  {
598  case ' ': break;
599  case ';': fNewModule=true; break;
600  default: if (fNewModule) iCount++; fNewModule=false; break;
601  }
602  szList++;
603  }
604  return iCount;
605 }

Here is the caller graph for this function:

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

Definition at line 446 of file Standard.cpp.

References SAppend().

Referenced by SAddModule().

447 {
448  if (szStr[0]) SAppend(szSepa,szStr);
449 }
void SAppend(const char *szSource, char *szTarget, int iMaxL)
Definition: Standard.cpp:235

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 560 of file Standard.cpp.

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

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

561 {
562  int iMod,iPos,iLen;
563  // Not a module
564  if (!SIsModule(szList,szModule,&iMod,fCaseSensitive)) return false;
565  // Get module start
566  iPos = 0;
567  if (iMod > 0) iPos = SCharPos(';',szList,iMod-1)+1;
568  // Get module length
569  iLen = SCharPos(';',szList+iPos);
570  if (iLen<0) iLen=SLen(szList); else iLen+=1;
571  // Delete module
572  SDelete(szList,iLen,iPos);
573  // Success
574  return true;
575 }
bool SIsModule(const char *szList, const char *szString, int *ipIndex, bool fCaseSensitive)
Definition: Standard.cpp:519
size_t SLen(const char *sptr)
Definition: Standard.h:74
void SDelete(char *szString, int iLen, int iPosition)
Definition: Standard.cpp:493
int SCharPos(char cTarget, const char *szInStr, int iIndex)
Definition: Standard.cpp:211

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 577 of file Standard.cpp.

References SGetModule(), and SRemoveModule().

Referenced by C4StartupScenSelDlg::KeyCheat2().

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 326 of file Standard.cpp.

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

327 {
328  while (str && *str)
329  { if (*str==fc) *str=tc; str++; }
330 }

Here is the caller graph for this function:

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

Definition at line 341 of file Standard.cpp.

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(), C4Markup::StripMarkup(), and C4Network2HTTPClient::UnpackPacket().

342 {
343  const char *cscr;
344  size_t indexlen,match=0;
345  if (!szString || !szIndex) return nullptr;
346  indexlen=SLen(szIndex);
347  for (cscr=szString; cscr && *cscr; cscr++)
348  {
349  if (*cscr==szIndex[match]) match++;
350  else match=0;
351  if (match>=indexlen) return cscr+1;
352  }
353  return nullptr;
354 }
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:

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

Definition at line 356 of file Standard.cpp.

References CharCapital(), and SLen().

Referenced by C4StartupNetListEntry::KeywordMatch().

357 {
358  const char *cscr;
359  size_t indexlen,match=0;
360  if (!szString || !szIndex) return nullptr;
361  indexlen=SLen(szIndex);
362  for (cscr=szString; cscr && *cscr; cscr++)
363  {
364  if (CharCapital(*cscr)==CharCapital(szIndex[match])) match++;
365  else match=0;
366  if (match>=indexlen) return cscr+1;
367  }
368  return nullptr;
369 }
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:

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

Definition at line 167 of file Standard.h.

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 }
std::string strprintf ( const char *  format,
  ... 
)

Definition at line 810 of file Standard.cpp.

References s, and vstrprintf().

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

811 {
812  va_list args;
813  va_start(args, format);
814  std::string s = vstrprintf(format, args);
815  va_end(args);
816  return s;
817 }
std::string vstrprintf(const char *format, va_list args)
Definition: Standard.cpp:794
#define s

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 98 of file Standard.cpp.

References s.

99 {
100  const char *s = str;
101  int sign = 1;
102  int32_t result = 0;
103  if (*s == '-')
104  {
105  sign = -1;
106  s++;
107  }
108  else if (*s == '+')
109  {
110  s++;
111  }
112  if (!*s)
113  {
114  // Abort if there are no digits to parse
115  if (scan_end) *scan_end = str;
116  return 0;
117  }
118  while (IsNumber(*s,base))
119  {
120  int value = ToNumber(*s++);
121  assert (value < base && value >= 0);
122  result *= base;
123  result += value;
124  }
125  if (scan_end != nullptr) *scan_end = s;
126  result *= sign;
127  return result;
128 }
#define s
bool SWildcardMatchEx ( const char *  szString,
const char *  szWildcard 
)

Definition at line 607 of file Standard.cpp.

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

608 {
609  // safety
610  if (!szString || !szWildcard) return false;
611  // match char-wise
612  const char *pWild = szWildcard, *pPos = szString;
613  const char *pLWild = nullptr, *pLPos = nullptr; // backtracking
614  while (*pWild || pLWild)
615  // string wildcard?
616  if (*pWild == '*')
617  { pLWild = ++pWild; pLPos = pPos; }
618  // nothing left to match?
619  else if (!*pPos)
620  break;
621  // equal or one-character-wildcard? proceed
622  else if (*pWild == '?' || *pWild == *pPos)
623  { pWild++; pPos++; }
624  // backtrack possible?
625  else if (pLPos)
626  { pWild = pLWild; pPos = ++pLPos; }
627  // match failed
628  else
629  return false;
630  // match complete if both strings are fully matched
631  return !*pWild && !*pPos;
632 }

Here is the caller graph for this function:

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

Definition at line 371 of file Standard.cpp.

Referenced by C4Game::DrawCrewOverheadText().

372 {
373  if (!szText) return;
374  // Scan string
375  char *cPos,*cpLastSpace=nullptr;
376  int iLineRun=0;
377  for (cPos=szText; *cPos; cPos++)
378  {
379  // Store last space
380  if (*cPos==cSpace) cpLastSpace=cPos;
381  // Separator encountered: reset line run
382  if (*cPos==cSepa) iLineRun=0;
383  // Need a break, insert at last space
384  if (iLineRun>=iMaxLine)
385  if (cpLastSpace)
386  { *cpLastSpace=cSepa; iLineRun=cPos - cpLastSpace; }
387  // Line run
388  iLineRun++;
389  }
390 }

Here is the caller graph for this function:

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

Definition at line 794 of file Standard.cpp.

References s.

Referenced by strprintf().

795 {
796  va_list argcopy;
797  va_copy(argcopy, args);
798  int size = vsnprintf(nullptr, 0, format, argcopy);
799  if (size < 0)
800  throw std::invalid_argument("invalid argument to strprintf");
801  va_end(argcopy);
802  std::string s;
803  s.resize(size + 1);
804  size = vsnprintf(&s[0], s.size(), format, args);
805  assert(size >= 0);
806  s.resize(size);
807  return s;
808 }
#define s

Here is the caller graph for this function:

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