Leviathan  0.8.0.0
Leviathan game engine
Leviathan::StringIterator Class Reference

Iterator class for getting parts of a string. More...

#include <StringIterator.h>

Public Member Functions

DLLEXPORT StringIterator (std::unique_ptr< StringDataIterator > &&iterator)
 Creates a iterator from the iterating object. More...
 
DLLEXPORT StringIterator (const std::wstring &text)
 Helper constructor for common string type. More...
 
DLLEXPORT StringIterator (const std::string &text)
 Helper constructor for common string type. More...
 
DLLEXPORT StringIterator (const std::wstring *text)
 Helper constructor for common string type. More...
 
DLLEXPORT StringIterator (const std::string *text)
 Helper constructor for common string type. More...
 
DLLEXPORT StringIterator ()
 Creates an empty iterator. More...
 
virtual DLLEXPORT ~StringIterator ()
 
DLLEXPORT void ReInit (std::unique_ptr< StringDataIterator > &&iterator)
 Changes the current iterator to the new iterator and goes to the beginning. More...
 
DLLEXPORT void ReInit (const std::wstring &text)
 Helper function for ReInit for common string type. More...
 
DLLEXPORT void ReInit (const std::string &text)
 Helper function for ReInit for common string type. More...
 
DLLEXPORT void ReInit (const std::wstring *text)
 Helper function for ReInit for common string type. More...
 
DLLEXPORT void ReInit (const std::string *text)
 Helper function for ReInit for common string type. More...
 
template<class RStrType >
std::unique_ptr< RStrType > GetStringInQuotes (QUOTETYPE quotes, int specialflags=0)
 Gets the next string in quotes. More...
 
template<class RStrType >
std::unique_ptr< RStrType > GetNextNumber (DECIMALSEPARATORTYPE decimal, int specialflags=0)
 Gets the next number. More...
 
template<class RStrType >
std::unique_ptr< RStrType > GetNextCharacterSequence (int stopcaseflags, int specialflags=0)
 Gets the next sequence of characters according to stopcaseflags. More...
 
template<class RStrType >
std::unique_ptr< RStrType > GetUntilEqualityAssignment (EQUALITYCHARACTER stopcase, int specialflags=0)
 Gets the string that is before the equality assignment. More...
 
template<class RStrType >
std::unique_ptr< RStrType > GetUntilEnd ()
 Gets all characters until the end. More...
 
template<class RStrType >
std::unique_ptr< RStrType > GetUntilLineEnd ()
 Gets all characters until a line end. More...
 
template<class RStrType >
std::unique_ptr< RStrType > GetUntilNextCharacterOrNothing (int charactertolookfor, int specialflags=0)
 Gets characters until a character or nothing if the specified character is not found. More...
 
template<class RStrType >
std::unique_ptr< RStrType > GetUntilNextCharacterOrAll (int charactertolookfor, int specialflags=0)
 Gets characters until a character or all remaining characters. More...
 
template<class RStrType >
std::unique_ptr< RStrType > GetUntilCharacterSequence (const RStrType &findstr, int specialflags=0)
 Gets all characters until a sequence is matched. More...
 
template<class RStrType >
std::unique_ptr< RStrType > GetStringInBracketsRecursive (int specialflags=0)
 Gets characters inside brackets. More...
 
void SkipWhiteSpace (int specialflags=0)
 Skips until characters that are not whitespace are found. More...
 
void SkipCharacters (int chartoskip, int additionalflag=0, int specialflags=0)
 Skips until chartoskip doesn't match the current character. More...
 
size_t GetPosition ()
 Returns the current reading position. More...
 
size_t GetCurrentLine ()
 Returns the current line the processing is happening. More...
 
int GetCharacter (size_t forward=0)
 Gets the character in the position current + forward. More...
 
bool IsAtNewLine ()
 Returns true if current character is a new line. More...
 
DLLEXPORT int GetPreviousCharacter ()
 Gets the previous character. More...
 
size_t GetLastValidCharIndex () const
 Returns the last valid index on the iterator. More...
 
bool MoveToNext ()
 Skips the current character and moves to the next. More...
 
DLLEXPORT void SkipLineEnd ()
 Skips characters until the line number changes. More...
 
bool IsOutOfBounds ()
 Returns true when the read position is valid. More...
 
bool IsInsideString ()
 
bool IsInsideComment ()
 
template<class STRSType >
std::unique_ptr< STRSType > GetSubstringFromIndexes (size_t firstcharacter, size_t lastcharacter) const
 Returns substring from the wanted indexes. More...
 
IteratorFindUntilData GetPositionsUntilACharacter (int character, int specialflags=0)
 Gets the position of the current character and the specified character. More...
 

Protected Member Functions

ITERATORCALLBACK_RETURNTYPE FindFirstQuotedString (IteratorPositionData *data, QUOTETYPE quotes, int specialflags)
 
ITERATORCALLBACK_RETURNTYPE FindNextNormalCharacterString (IteratorPositionData *data, int stopflags, int specialflags)
 
ITERATORCALLBACK_RETURNTYPE FindNextNumber (IteratorNumberFindData *data, DECIMALSEPARATORTYPE decimal, int specialflags)
 
ITERATORCALLBACK_RETURNTYPE FindUntilEquality (IteratorAssignmentData *data, EQUALITYCHARACTER equality, int specialflags)
 
ITERATORCALLBACK_RETURNTYPE SkipSomething (IteratorCharacterData &data, const int additionalskip, const int specialflags)
 
ITERATORCALLBACK_RETURNTYPE FindUntilSpecificCharacter (IteratorFindUntilData *data, int character, int specialflags)
 
ITERATORCALLBACK_RETURNTYPE FindUntilNewLine (IteratorFindUntilData *data)
 
ITERATORCALLBACK_RETURNTYPE FindInMatchingParentheses (IteratorNestingLevelData *data, int left, int right, int specialflags)
 
template<class AcceptStr >
ITERATORCALLBACK_RETURNTYPE FindUntilSequence (IteratorUntilSequenceData< AcceptStr > *data, int specialflags)
 

Detailed Description

Iterator class for getting parts of a string.

Definition at line 135 of file StringIterator.h.

Constructor & Destructor Documentation

◆ StringIterator() [1/6]

DLLEXPORT Leviathan::StringIterator::StringIterator ( std::unique_ptr< StringDataIterator > &&  iterator)

Creates a iterator from the iterating object.

Definition at line 10 of file StringIterator.cpp.

11  :
12  HandlesDelete(true),
13  DataIterator(iterator.release())
14 {}

◆ StringIterator() [2/6]

DLLEXPORT Leviathan::StringIterator::StringIterator ( const std::wstring &  text)

Helper constructor for common string type.

Definition at line 20 of file StringIterator.cpp.

20  :
21  HandlesDelete(true), DataIterator(new StringClassDataIterator<wstring>(text))
22 {}
Iterator for string types.

◆ StringIterator() [3/6]

DLLEXPORT Leviathan::StringIterator::StringIterator ( const std::string &  text)

Helper constructor for common string type.

Definition at line 16 of file StringIterator.cpp.

16  :
17  HandlesDelete(true), DataIterator(new StringClassDataIterator<string>(text))
18 {}
Iterator for string types.

◆ StringIterator() [4/6]

DLLEXPORT Leviathan::StringIterator::StringIterator ( const std::wstring *  text)

Helper constructor for common string type.

Parameters
textPointer to a string that won't be deleted by this

Definition at line 24 of file StringIterator.cpp.

24  :
25  HandlesDelete(true), DataIterator(new StringClassPointerIterator<wstring>(text))
26 {}
Iterator that doesn&#39;t hold own copy of a string.

◆ StringIterator() [5/6]

DLLEXPORT Leviathan::StringIterator::StringIterator ( const std::string *  text)

Helper constructor for common string type.

Parameters
textPointer to a string that won't be deleted by this

Definition at line 28 of file StringIterator.cpp.

28  :
29  HandlesDelete(true), DataIterator(new StringClassPointerIterator<string>(text))
30 {}
Iterator that doesn&#39;t hold own copy of a string.

◆ StringIterator() [6/6]

DLLEXPORT StringIterator::StringIterator ( )

Creates an empty iterator.

Use ReInit to fill with data

Definition at line 8 of file StringIterator.cpp.

8 {}

◆ ~StringIterator()

DLLEXPORT Leviathan::StringIterator::~StringIterator ( )
virtual

Definition at line 32 of file StringIterator.cpp.

33 {
34  if(HandlesDelete) {
35 
36  SAFE_DELETE(DataIterator);
37  }
38 }
#define SAFE_DELETE(x)
Definition: Define.h:147

Member Function Documentation

◆ FindFirstQuotedString()

ITERATORCALLBACK_RETURNTYPE Leviathan::StringIterator::FindFirstQuotedString ( IteratorPositionData data,
QUOTETYPE  quotes,
int  specialflags 
)
inlineprotected

Definition at line 1049 of file StringIterator.h.

1051  {
1052  bool TakeChar = true;
1053  bool End = false;
1054 
1055  if(specialflags & SPECIAL_ITERATOR_ONNEWLINE_STOP && IsAtNewLine()) {
1056  ITR_FUNCDEBUG("Stopping to new line");
1057 
1058  if(data->Positions.Start) {
1059  // Set the last character to two before this
1060  // (skip the current and " and end there)
1061  int previouscheck = GetPreviousCharacter();
1062 
1063  // Check do we need to go back 2 characters or just one //
1064  if((quotes == QUOTETYPE_BOTH &&
1065  (previouscheck == '"' || previouscheck == '\'')) ||
1066  (quotes == QUOTETYPE_DOUBLEQUOTES && previouscheck == '"') ||
1067  (quotes == QUOTETYPE_SINGLEQUOTES && previouscheck == '\'')) {
1068  ITR_FUNCDEBUG("Going back over an extra quote character");
1069  data->Positions.End = GetPosition() - 2;
1070  } else {
1071  data->Positions.End = GetPosition() - 1;
1072  }
1073 
1074  ITR_FUNCDEBUG("Ending to new line, end is now: " +
1075  Convert::ToString(data->Positions.End));
1076  }
1077 
1078  SkipLineEnd();
1080  }
1081 
1082  int currentcharacter = GetCharacter();
1083 
1084  switch(quotes) {
1085  case QUOTETYPE_BOTH: {
1086  if(CurrentFlags & ITERATORFLAG_SET_INSIDE_STRING) {
1087  // check if we are on the quotes, because we don't want those //
1088  if(currentcharacter == '"' || currentcharacter == '\'') {
1089  // if we aren't ignoring special disallow //
1090  if(!(CurrentFlags & ITERATORFLAG_SET_IGNORE_SPECIAL)) {
1091  TakeChar = false;
1092  ITR_FUNCDEBUG("Found quote character");
1093  }
1094  }
1095 
1096  } else {
1097  End = true;
1098  ITR_FUNCDEBUG("Outside quotes");
1099  }
1100  } break;
1101  case QUOTETYPE_SINGLEQUOTES: {
1102  if(CurrentFlags & ITERATORFLAG_SET_INSIDE_STRING_SINGLE) {
1103  // check if we are on the quotes, because we don't want those //
1104  if(currentcharacter == '\'') {
1105  // if we aren't ignoring special disallow //
1106  if(!(CurrentFlags & ITERATORFLAG_SET_IGNORE_SPECIAL)) {
1107  TakeChar = false;
1108  ITR_FUNCDEBUG("Found quote character");
1109  }
1110  }
1111 
1112  } else {
1113  End = true;
1114  ITR_FUNCDEBUG("Outside quotes");
1115  }
1116  } break;
1117  case QUOTETYPE_DOUBLEQUOTES: {
1118  if(CurrentFlags & ITERATORFLAG_SET_INSIDE_STRING_DOUBLE) {
1119  // check if we are on the quotes, because we don't want those //
1120  if(currentcharacter == '"') {
1121  // if we aren't ignoring special disallow //
1122  if(!(CurrentFlags & ITERATORFLAG_SET_IGNORE_SPECIAL)) {
1123  TakeChar = false;
1124  ITR_FUNCDEBUG("Found quote character");
1125  }
1126  }
1127 
1128  } else {
1129  End = true;
1130  ITR_FUNCDEBUG("Outside quotes");
1131  }
1132  } break;
1133  }
1134 
1135  // If we have found a character this is on the ending quote //
1136  if(!TakeChar && data->Positions.Start) {
1137 
1138  // Set the last character to the one before this (skip the " and end there) //
1139  data->Positions.End = GetPosition() - 1;
1140  ITR_FUNCDEBUG(
1141  "On ending quote, end is now: " + Convert::ToString(data->Positions.End));
1142  }
1143 
1144  if(End) {
1145  // if we have found at least a character we can end this here //
1146  if(data->Positions.Start) {
1147  // Set the last character to two before this
1148  // (skip the current and " and end there)
1149  data->Positions.End = GetPosition() - 2;
1150  ITR_FUNCDEBUG("Ending outside quotes, end is now: " +
1151  Convert::ToString(data->Positions));
1153  }
1154  } else if(TakeChar) {
1155  // check is this first quoted character //
1156  if(!data->Positions.Start) {
1157  // first position! //
1158  data->Positions.Start = GetPosition();
1159  ITR_FUNCDEBUG(
1160  "First character found: " + Convert::ToString(data->Positions.Start));
1161  }
1162  }
1163 
1165  }
\ is found, next special character will be ignored
DLLEXPORT int GetPreviousCharacter()
Gets the previous character.
int GetCharacter(size_t forward=0)
Gets the character in the position current + forward.
#define ITR_FUNCDEBUG(x)
DLLEXPORT void SkipLineEnd()
Skips characters until the line number changes.
static std::string ToString(const T &val)
Definition: Convert.h:72
Iterator is currently inside double quoted string, "like this".
size_t GetPosition()
Returns the current reading position.
Iterator is currently inside a string.
Iterator is currently inside single quoted string, &#39;like this&#39;.
bool IsAtNewLine()
Returns true if current character is a new line.

◆ FindInMatchingParentheses()

ITERATORCALLBACK_RETURNTYPE Leviathan::StringIterator::FindInMatchingParentheses ( IteratorNestingLevelData data,
int  left,
int  right,
int  specialflags 
)
inlineprotected

Definition at line 1585 of file StringIterator.h.

1587  {
1588  // Ignore if ignoring special characters //
1589  if(!(CurrentFlags & ITERATORFLAG_SET_IGNORE_SPECIAL) &&
1590  !(CurrentFlags & ITERATORFLAG_SET_INSIDE_STRING)) {
1591  if(specialflags & SPECIAL_ITERATOR_ONNEWLINE_STOP && IsAtNewLine()) {
1592 
1593  // Invalid, always //
1595  }
1596 
1597  int currentcharacter = GetCharacter();
1598 
1599  // Nesting level starts //
1600  if(currentcharacter == left) {
1601 
1602  ++data->NestingLevel;
1603 
1604  if(data->NestingLevel > 1) {
1605 
1606  // There where multiple lefts in a row, like "[[[...]]]"
1607  goto isinsidevalidleftrightpair;
1608  }
1609 
1611  }
1612 
1613  // One nesting level is ending //
1614  if(currentcharacter == right) {
1615 
1616  --data->NestingLevel;
1617 
1618  if(data->NestingLevel == 0) {
1619 
1620  data->Positions.End = GetPosition() - 1;
1622  }
1623  }
1624  }
1625 
1626  isinsidevalidleftrightpair:
1627 
1628  if(!data->Positions.Start && data->NestingLevel > 0) {
1629 
1630  data->Positions.Start = GetPosition();
1631  }
1632 
1634  }
\ is found, next special character will be ignored
int GetCharacter(size_t forward=0)
Gets the character in the position current + forward.
size_t GetPosition()
Returns the current reading position.
Iterator is currently inside a string.
bool IsAtNewLine()
Returns true if current character is a new line.

◆ FindNextNormalCharacterString()

ITERATORCALLBACK_RETURNTYPE Leviathan::StringIterator::FindNextNormalCharacterString ( IteratorPositionData data,
int  stopflags,
int  specialflags 
)
inlineprotected

Definition at line 1167 of file StringIterator.h.

1169  {
1170  bool IsValid = true;
1171 
1172  if(specialflags & SPECIAL_ITERATOR_ONNEWLINE_STOP && IsAtNewLine()) {
1173  ITR_FUNCDEBUG("Stopping to new line");
1174 
1175  if(data->Positions.Start) {
1176  // ended //
1177  data->Positions.End = GetPosition() - 1;
1178  ITR_FUNCDEBUG("Ending to new line, end is now: " +
1179  Convert::ToString(data->Positions.End));
1180  }
1181 
1182  SkipLineEnd();
1184  }
1185 
1186  int currentcharacter = GetCharacter();
1187 
1188  // If set this is invalid inside comments //
1189  if((specialflags & SPECIAL_ITERATOR_HANDLECOMMENTS_ASSTRING) &&
1190  (CurrentFlags & ITERATORFLAG_SET_INSIDE_COMMENT)) {
1191  IsValid = false;
1192  goto invalidcodelabelunnormalcharacter;
1193  }
1194 
1195  if((stopflags & UNNORMALCHARACTER_TYPE_LOWCODES ||
1196  stopflags & UNNORMALCHARACTER_TYPE_WHITESPACE) &&
1197  !(CurrentFlags & ITERATORFLAG_SET_INSIDE_STRING)) {
1198  if(currentcharacter <= ' ') {
1199  IsValid = false;
1200  goto invalidcodelabelunnormalcharacter;
1201  }
1202  }
1203 
1204  if(stopflags & UNNORMALCHARACTER_TYPE_NON_ASCII) {
1205 
1206  if(CurrentFlags & ITERATORFLAG_SET_INSIDE_STRING ||
1207  !((currentcharacter >= '0' && currentcharacter <= '9') ||
1208  (currentcharacter >= 'A' && currentcharacter <= 'Z') ||
1209  (currentcharacter >= 'a' && currentcharacter <= 'z'))) {
1210  IsValid = false;
1211  goto invalidcodelabelunnormalcharacter;
1212  }
1213  }
1214 
1216  !(CurrentFlags & ITERATORFLAG_SET_INSIDE_STRING) &&
1217  !(CurrentFlags & ITERATORFLAG_SET_IGNORE_SPECIAL)) {
1218  if(((currentcharacter <= '/' && currentcharacter >= '!') ||
1219  (currentcharacter <= '@' && currentcharacter >= ':') ||
1220  (currentcharacter <= '`' && currentcharacter >= '[') ||
1221  (currentcharacter <= '~' && currentcharacter >= '{')) &&
1222  !(currentcharacter == '_' || currentcharacter == '-')) {
1223  IsValid = false;
1224  goto invalidcodelabelunnormalcharacter;
1225  }
1226  }
1227 
1228  if(IsValid) {
1229  // check is this first character //
1230  if(!data->Positions.Start) {
1231  // first position! //
1232  data->Positions.Start = GetPosition();
1233  ITR_FUNCDEBUG("Started: " + Convert::ToString(data->Positions.Start));
1234  }
1235 
1236  } else {
1237 
1238  invalidcodelabelunnormalcharacter:
1239 
1240 
1241  // check for end //
1242  if(data->Positions.Start) {
1243  // ended //
1244  data->Positions.End = GetPosition() - 1;
1245  ITR_FUNCDEBUG("End now: " + Convert::ToString(data->Positions.End));
1247  }
1248  }
1249 
1251  }
\ is found, next special character will be ignored
int GetCharacter(size_t forward=0)
Gets the character in the position current + forward.
#define ITR_FUNCDEBUG(x)
DLLEXPORT void SkipLineEnd()
Skips characters until the line number changes.
static std::string ToString(const T &val)
Definition: Convert.h:72
Causes comments to be handled as whitespace/delimiting.
size_t GetPosition()
Returns the current reading position.
Iterator is currently inside a string.
bool IsAtNewLine()
Returns true if current character is a new line.

◆ FindNextNumber()

ITERATORCALLBACK_RETURNTYPE Leviathan::StringIterator::FindNextNumber ( IteratorNumberFindData data,
DECIMALSEPARATORTYPE  decimal,
int  specialflags 
)
inlineprotected

Definition at line 1253 of file StringIterator.h.

1255  {
1256  // Check is the current element a part of a number //
1257 
1258  bool IsValid = false;
1259 
1260  if(specialflags & SPECIAL_ITERATOR_ONNEWLINE_STOP && IsAtNewLine()) {
1261  ITR_FUNCDEBUG("Stopping to new line");
1262 
1263  if(data->Positions.Start) {
1264  // ended //
1265  data->Positions.End = GetPosition() - 1;
1266  ITR_FUNCDEBUG("Ending to new line, end is now: " +
1267  Convert::ToString(data->Positions.End));
1268  }
1269 
1270  SkipLineEnd();
1272  }
1273 
1274  // Comments might be skipped //
1275  if(!(specialflags & SPECIAL_ITERATOR_HANDLECOMMENTS_ASSTRING) ||
1276  !(CurrentFlags & ITERATORFLAG_SET_INSIDE_COMMENT)) {
1277  int currentcharacter = GetCharacter();
1278 
1279  if((currentcharacter >= 48) && (currentcharacter <= 57)) {
1280  // Is a plain old digit //
1281  IsValid = true;
1282 
1283  } else {
1284  // Check is it a decimal separator (1 allowed)
1285  // or a negativity sign in front
1286  if(currentcharacter == '+' || currentcharacter == '-') {
1287 
1288  if((data->DigitsFound < 1) && (!data->NegativeFound)) {
1289  IsValid = true;
1290  }
1291  data->NegativeFound = true;
1292  } else if(((currentcharacter == '.') &&
1293  ((decimal == DECIMALSEPARATORTYPE_DOT) ||
1294  (decimal == DECIMALSEPARATORTYPE_BOTH))) ||
1295  ((currentcharacter == ',') &&
1296  ((decimal == DECIMALSEPARATORTYPE_COMMA) ||
1297  (decimal == DECIMALSEPARATORTYPE_BOTH)))) {
1298  if((!data->DecimalFound) && (data->DigitsFound > 0)) {
1299  IsValid = true;
1300  data->DecimalFound = true;
1301  }
1302  }
1303  }
1304  } else {
1305  ITR_FUNCDEBUG("Ignoring inside a comment");
1306  }
1307 
1308  if(IsValid) {
1309  // check is this first digit //
1310  data->DigitsFound++;
1311  if(!data->Positions.Start) {
1312  // first position! //
1313 
1314  data->Positions.Start = GetPosition();
1315  ITR_FUNCDEBUG("Data started: " + Convert::ToString(data->Positions.Start));
1316  }
1317 
1318  } else {
1319  // check for end //
1320  if(data->Positions.Start) {
1321  // ended //
1322  data->Positions.End = GetPosition() - 1;
1323  ITR_FUNCDEBUG("End now: " + Convert::ToString(data->Positions.End));
1325  }
1326  }
1328  }
int GetCharacter(size_t forward=0)
Gets the character in the position current + forward.
#define ITR_FUNCDEBUG(x)
DLLEXPORT void SkipLineEnd()
Skips characters until the line number changes.
static std::string ToString(const T &val)
Definition: Convert.h:72
Causes comments to be handled as whitespace/delimiting.
size_t GetPosition()
Returns the current reading position.
bool IsAtNewLine()
Returns true if current character is a new line.

◆ FindUntilEquality()

ITERATORCALLBACK_RETURNTYPE Leviathan::StringIterator::FindUntilEquality ( IteratorAssignmentData data,
EQUALITYCHARACTER  equality,
int  specialflags 
)
inlineprotected

Definition at line 1330 of file StringIterator.h.

1332  {
1333  // check is current element a valid element //
1334  bool IsValid = true;
1335  bool IsStop = false;
1336 
1337  if(specialflags & SPECIAL_ITERATOR_ONNEWLINE_STOP && IsAtNewLine()) {
1338  ITR_FUNCDEBUG("Stopping to new line");
1339 
1340  SkipLineEnd();
1342  }
1343 
1344  // Comments cannot be part of this //
1345  if((specialflags & SPECIAL_ITERATOR_HANDLECOMMENTS_ASSTRING) &&
1346  (CurrentFlags & ITERATORFLAG_SET_INSIDE_COMMENT)) {
1347  // Not valid inside a comment //
1348  ITR_FUNCDEBUG("Comment skipped");
1349  IsValid = false;
1350 
1351  } else {
1352 
1353  int charvalue = GetCharacter();
1354 
1355  // Skip if this is a space //
1356  if(charvalue < 33) {
1357  // Not allowed in a name //
1358  ITR_FUNCDEBUG("Whitespace skipped");
1359  IsValid = false;
1360  }
1361 
1362  if(equality == EQUALITYCHARACTER_TYPE_ALL) {
1363  // check for all possible value separators //
1364  if(charvalue == '=' || charvalue == ':') {
1365 
1366  if(!(CurrentFlags & ITERATORFLAG_SET_IGNORE_SPECIAL)) {
1367  // If ignored don't stop //
1368  ITR_FUNCDEBUG("Found = or :");
1369  IsStop = true;
1370  }
1371  }
1372  } else if(equality == EQUALITYCHARACTER_TYPE_EQUALITY) {
1373  // Check for an equality sign //
1374  if(charvalue == '=') {
1375  if(!(CurrentFlags & ITERATORFLAG_SET_IGNORE_SPECIAL)) {
1376  ITR_FUNCDEBUG("Found =");
1377  IsStop = true;
1378  }
1379  }
1380  } else if(equality == EQUALITYCHARACTER_TYPE_DOUBLEDOTSTYLE) {
1381  // Check does it match the characters //
1382  if(charvalue == ':') {
1383  if(!(CurrentFlags & ITERATORFLAG_SET_IGNORE_SPECIAL)) {
1384  ITR_FUNCDEBUG("Found :");
1385  IsStop = true;
1386  }
1387  }
1388  }
1389  }
1390 
1391  if(!IsStop) {
1392  // end if end already found //
1393  if(data->SeparatorFound) {
1394  ITR_FUNCDEBUG("Found stop");
1396  }
1397  } else {
1398  data->SeparatorFound = true;
1399  IsValid = false;
1400  }
1401 
1402  if(IsValid) {
1403  // Check is this the first character //
1404  if(!data->Positions.Start) {
1405  // first position! //
1406  data->Positions.Start = GetPosition();
1407  ITR_FUNCDEBUG("Data started: " + Convert::ToString(data->Positions.Start));
1408 
1409  } else {
1410  // Set end to this valid character //
1411  data->Positions.End = GetPosition();
1412  ITR_FUNCDEBUG("End now: " + Convert::ToString(data->Positions.End));
1413  }
1414  }
1415 
1416 
1418  }
\ is found, next special character will be ignored
int GetCharacter(size_t forward=0)
Gets the character in the position current + forward.
#define ITR_FUNCDEBUG(x)
DLLEXPORT void SkipLineEnd()
Skips characters until the line number changes.
static std::string ToString(const T &val)
Definition: Convert.h:72
Causes comments to be handled as whitespace/delimiting.
size_t GetPosition()
Returns the current reading position.
bool IsAtNewLine()
Returns true if current character is a new line.

◆ FindUntilNewLine()

ITERATORCALLBACK_RETURNTYPE Leviathan::StringIterator::FindUntilNewLine ( IteratorFindUntilData data)
inlineprotected

Definition at line 1546 of file StringIterator.h.

1547  {
1548  // Continue if the current character is a new line character //
1549 
1550  // All line separator characters should be here //
1551  if(IsAtNewLine()) {
1552 
1553  if(!data->FoundEnd) {
1554  // Ignore the first new line //
1555  data->FoundEnd = true;
1556  ITR_FUNCDEBUG("Ignoring first newline character");
1557  goto positionisvalidlabelstringiteratorfindnewline;
1558  }
1559 
1560  // This is a new line character //
1561  ITR_FUNCDEBUG("Found newline character");
1562 
1563  // End before this character //
1564  data->Positions.End = GetPosition() - 1;
1565  ITR_FUNCDEBUG("Ending here: " + Convert::ToString(data->Positions));
1566 
1567  SkipLineEnd();
1569  }
1570 
1571  positionisvalidlabelstringiteratorfindnewline:
1572 
1573  // Set position //
1574  if(!data->Positions.Start) {
1575 
1576  // End before this character //
1577  data->Positions.Start = GetPosition();
1578  data->FoundEnd = true;
1579  ITR_FUNCDEBUG("Data started: " + Convert::ToString(data->Positions));
1580  }
1581 
1583  }
#define ITR_FUNCDEBUG(x)
DLLEXPORT void SkipLineEnd()
Skips characters until the line number changes.
static std::string ToString(const T &val)
Definition: Convert.h:72
size_t GetPosition()
Returns the current reading position.
bool IsAtNewLine()
Returns true if current character is a new line.

◆ FindUntilSequence()

template<class AcceptStr >
ITERATORCALLBACK_RETURNTYPE Leviathan::StringIterator::FindUntilSequence ( IteratorUntilSequenceData< AcceptStr > *  data,
int  specialflags 
)
inlineprotected

Definition at line 1639 of file StringIterator.h.

1641  {
1642  // First check if this is a line end //
1643  int curcharacter = GetCharacter();
1644 
1645  if(specialflags & SPECIAL_ITERATOR_ONNEWLINE_STOP && IsAtNewLine()) {
1646 
1647  // Set the end to one before this, if found any //
1648  if(data->Positions.Start) {
1649 
1650  data->Positions.End = GetPosition() - 1;
1651  }
1652 
1653  SkipLineEnd();
1655  }
1656 
1657  // We may not be inside strings nor comments for checking //
1658  if(!(CurrentFlags & ITERATORFLAG_SET_INSIDE_STRING) &&
1659  (!(CurrentFlags & ITERATORFLAG_SET_INSIDE_COMMENT) ||
1660  !(specialflags & SPECIAL_ITERATOR_HANDLECOMMENTS_ASSTRING))) {
1661  // Check do we match the current position //
1662  if(curcharacter == data->StringToMatch[data->CurMatchedIndex]) {
1663 
1664  // Found a matching character //
1665 
1666  // Move to next match position and don't yet verify if this is a valid
1667  // character
1668  ++data->CurMatchedIndex;
1669 
1670  if(data->CurMatchedIndex >= data->StringToMatch.size()) {
1671 
1672  // End found //
1674  }
1675 
1677  }
1678  }
1679 
1680  // Go back to beginning of matching //
1681  data->CurMatchedIndex = 0;
1682 
1683  // All is fine //
1684  if(!data->Positions.Start) {
1685 
1686  data->Positions.Start = GetPosition();
1687  data->Positions.End = data->Positions.Start;
1688  } else {
1689 
1690  // This might be poisonous to performance, but this gets the job done //
1691  data->Positions.End = GetPosition();
1692  }
1693 
1695  }
int GetCharacter(size_t forward=0)
Gets the character in the position current + forward.
DLLEXPORT void SkipLineEnd()
Skips characters until the line number changes.
Causes comments to be handled as whitespace/delimiting.
size_t GetPosition()
Returns the current reading position.
Iterator is currently inside a string.
bool IsAtNewLine()
Returns true if current character is a new line.

◆ FindUntilSpecificCharacter()

ITERATORCALLBACK_RETURNTYPE Leviathan::StringIterator::FindUntilSpecificCharacter ( IteratorFindUntilData data,
int  character,
int  specialflags 
)
inlineprotected

Definition at line 1458 of file StringIterator.h.

1460  {
1461  // Can this character be added //
1462  bool ValidChar = true;
1463 
1464  if(specialflags & SPECIAL_ITERATOR_ONNEWLINE_STOP && IsAtNewLine()) {
1465  ITR_FUNCDEBUG("Stopping to new line");
1466 
1467  if(data->Positions.Start) {
1468  // This should be fine to get here //
1469  data->Positions.End = GetPosition() - 1;
1470  ITR_FUNCDEBUG("Ending to new line, end is now: " +
1471  Convert::ToString(data->Positions.End));
1472  }
1473 
1474  // Make sure to not return until end of the whole string //
1475  data->NewLineBreak = true;
1476 
1477  SkipLineEnd();
1479  }
1480 
1481  int tmpchara = GetCharacter();
1482 
1483  // We can just continue if we are inside a string //
1484  if(!(CurrentFlags & ITERATORFLAG_SET_INSIDE_STRING) &&
1485  !((specialflags & SPECIAL_ITERATOR_HANDLECOMMENTS_ASSTRING) &&
1486  (CurrentFlags & ITERATORFLAG_SET_INSIDE_COMMENT))) {
1487  // Check did we encounter stop character //
1488 #ifdef ALLOW_DEBUG
1489  if(DebugMode) {
1490 
1491  std::string value = "Trying to match: ";
1492  utf8::append(tmpchara, std::back_inserter(value));
1493  value += "==" + Convert::ToString(tmpchara);
1494 
1495  Logger::Get()->Write("Iterator: procfunc: " + value);
1496  }
1497 #endif // ALLOW_DEBUG
1498 
1499  if(tmpchara == character) {
1500  // Skip if ignoring special characters //
1501  if(!(CurrentFlags & ITERATORFLAG_SET_IGNORE_SPECIAL)) {
1502  // Not valid character //
1503  ValidChar = false;
1504  ITR_FUNCDEBUG("Found match");
1505  // We must have started to encounter the stop character //
1506  if(data->Positions.Start) {
1507  // We encountered the stop character //
1508  data->FoundEnd = true;
1509  ITR_FUNCDEBUG("Encountered end");
1510  }
1511  }
1512  }
1513  } else {
1514 #ifdef ALLOW_DEBUG
1515  if((CurrentFlags & ITERATORFLAG_SET_INSIDE_STRING)) {
1516  ITR_FUNCDEBUG("Ignoring inside string");
1517  }
1518  if((specialflags & SPECIAL_ITERATOR_HANDLECOMMENTS_ASSTRING) &&
1519  (CurrentFlags & ITERATORFLAG_SET_INSIDE_COMMENT)) {
1520  ITR_FUNCDEBUG("Ignoring inside comment");
1521  }
1522 #endif // _DEBUG
1523  }
1524 
1525  if(ValidChar) {
1526  // valid character set start if not already set //
1527  if(!data->Positions.Start) {
1528  data->Positions.Start = GetPosition();
1529  data->Positions.End = data->Positions.Start;
1530  ITR_FUNCDEBUG("Data started: " + Convert::ToString(data->Positions.Start));
1531  }
1533  }
1534  // let's stop if we have found something //
1535  if(data->Positions.Start) {
1536  // This should be fine to get here //
1537  data->Positions.End = GetPosition() - 1;
1538  ITR_FUNCDEBUG("Ending here: " + Convert::ToString(data->Positions.End));
1540  }
1541 
1542  // haven't found anything, we'll need to find something //
1544  }
DLLEXPORT void Write(const std::string &data) override
Definition: Logger.cpp:113
\ is found, next special character will be ignored
int GetCharacter(size_t forward=0)
Gets the character in the position current + forward.
#define ITR_FUNCDEBUG(x)
DLLEXPORT void SkipLineEnd()
Skips characters until the line number changes.
static std::string ToString(const T &val)
Definition: Convert.h:72
static DLLEXPORT Logger * Get()
Definition: Logger.cpp:106
Causes comments to be handled as whitespace/delimiting.
size_t GetPosition()
Returns the current reading position.
Iterator is currently inside a string.
bool IsAtNewLine()
Returns true if current character is a new line.
octet_iterator append(uint32_t cp, octet_iterator result)
The library API - functions intended to be called by the users.
Definition: checked.h:73

◆ GetCharacter()

int Leviathan::StringIterator::GetCharacter ( size_t  forward = 0)
inline

Gets the character in the position current + forward.

Definition at line 501 of file StringIterator.h.

502  {
503 
504  // Special case for current character //
505  if(!forward) {
506 
507  if(!CurrentStored) {
508 
509  if(!DataIterator->GetNextCharCode(CurrentCharacter, 0)) {
510 
511  // Invalid position //
512  return -1;
513  }
514 
515  CurrentStored = true;
516 
518  "Current char: (" + Convert::CodePointToUtf8(CurrentCharacter) + ")");
519  }
520 
521  return CurrentCharacter;
522  }
523 
524  // Get the character from our iterator and store it to a temporary value
525  // and then return it
526  int tmpval = -1;
527  DataIterator->GetNextCharCode(tmpval, forward);
528 
529  ITR_COREDEBUG("Peek forward char: (" + Convert::CodePointToUtf8(tmpval) + ")");
530 
531  return tmpval;
532  }
virtual bool GetNextCharCode(int &codepointreceiver, size_t forward)=0
Gets the next character unicode code point (usually an ascii value)
#define ITR_COREDEBUG(x)
static DLLEXPORT std::string CodePointToUtf8(int32_t codepoint)
Encodes a Unicode code point as an UTF8 string.
Definition: Convert.cpp:137

◆ GetCurrentLine()

size_t Leviathan::StringIterator::GetCurrentLine ( )
inline

Returns the current line the processing is happening.

Definition at line 494 of file StringIterator.h.

495  {
496 
497  return DataIterator->GetCurrentLineNumber();
498  }
virtual DLLEXPORT size_t GetCurrentLineNumber() const
Returns the 1 based line number.

◆ GetLastValidCharIndex()

size_t Leviathan::StringIterator::GetLastValidCharIndex ( ) const
inline

Returns the last valid index on the iterator.

Definition at line 549 of file StringIterator.h.

550  {
551 
552  return DataIterator->GetLastValidIteratorPosition();
553  }
virtual size_t GetLastValidIteratorPosition() const =0
Gets the last valid index of the underlying string (not the last character but the last byte) ...

◆ GetNextCharacterSequence()

template<class RStrType >
std::unique_ptr<RStrType> Leviathan::StringIterator::GetNextCharacterSequence ( int  stopcaseflags,
int  specialflags = 0 
)
inline

Gets the next sequence of characters according to stopcaseflags.

Parameters
stopcaseflagsSpecifies until what type of characters this string is read. Should be created by using UNNORMALCHARACTER as bit flags inside the argument int
Returns
The string found or NULL

Definition at line 238 of file StringIterator.h.

239  {
240  // Setup the result object //
241  IteratorPositionData data;
242 
243  // Iterate with our getting function //
244  StartIterating(specialflags, &StringIterator::FindNextNormalCharacterString, &data,
245  stopcaseflags, specialflags);
246 
247  // check for nothing found //
248  if(!data.Positions.Start && !data.Positions.Start) {
249 
250  return NULL;
251  }
252 
253  // Make sure end is fine //
254  if(!data.Positions.End)
255  data.Positions.End = GetLastValidCharIndex();
256 
257 
258  // Return the wanted part //
259  return GetSubstringFromIndexes<RStrType>(data.Positions.Start, data.Positions.End);
260  }
size_t GetLastValidCharIndex() const
Returns the last valid index on the iterator.
ITERATORCALLBACK_RETURNTYPE FindNextNormalCharacterString(IteratorPositionData *data, int stopflags, int specialflags)

◆ GetNextNumber()

template<class RStrType >
std::unique_ptr<RStrType> Leviathan::StringIterator::GetNextNumber ( DECIMALSEPARATORTYPE  decimal,
int  specialflags = 0 
)
inline

Gets the next number.

This function will skip until it finds a number and returns the number string according to the decimal parameter. If the type is DECIMALSEPARATORTYPE_NONE decimal numbers are only read until the dot

Returns
The string found or NULL

Definition at line 207 of file StringIterator.h.

208  {
209  // Setup the result object //
210  IteratorNumberFindData data;
211 
212  // iterate over the string getting the proper part //
213  // Iterate with our getting function //
214  StartIterating(
215  specialflags, &StringIterator::FindNextNumber, &data, decimal, specialflags);
216 
217  // Check for nothing found //
218  if(!data.Positions.Start) {
219  return nullptr;
220  }
221 
222  // create substring of the wanted part //
223 
224 
225  // Make sure end is fine //
226  if(!data.Positions.End)
227  data.Positions.End = GetLastValidCharIndex();
228 
229  // Return the wanted part //
230  return GetSubstringFromIndexes<RStrType>(data.Positions.Start, data.Positions.End);
231  }
size_t GetLastValidCharIndex() const
Returns the last valid index on the iterator.
ITERATORCALLBACK_RETURNTYPE FindNextNumber(IteratorNumberFindData *data, DECIMALSEPARATORTYPE decimal, int specialflags)

◆ GetPosition()

size_t Leviathan::StringIterator::GetPosition ( )
inline

Returns the current reading position.

Note
This might be somewhat expensive operation based on the underlying StringDataIterator class (mostly expensive for UTF8 strings)

Definition at line 487 of file StringIterator.h.

488  {
489 
490  return DataIterator->CurrentIteratorPosition();
491  }
virtual size_t CurrentIteratorPosition() const =0
Gets the position of the iterator, for use with ReturnSubString and others.

◆ GetPositionsUntilACharacter()

IteratorFindUntilData Leviathan::StringIterator::GetPositionsUntilACharacter ( int  character,
int  specialflags = 0 
)
inline

Gets the position of the current character and the specified character.

Definition at line 626 of file StringIterator.h.

627  {
628  // Setup the result object //
629  IteratorFindUntilData data;
630 
631  // Iterate with our getting function //
632  StartIterating(specialflags, &StringIterator::FindUntilSpecificCharacter, &data,
633  character, specialflags);
634 
635 #ifdef ITERATOR_ALLOW_DEBUG
636  if(DebugMode) {
637  Logger::Get()->Write("Iterator: find GetPositionsUntilACharacter, positions: " +
638  Convert::ToString(data.Positions) +
639  ", found: " + Convert::ToString(data.FoundEnd));
640  }
641 #endif // _DEBUG
642 
643  return data;
644  }
DLLEXPORT void Write(const std::string &data) override
Definition: Logger.cpp:113
static std::string ToString(const T &val)
Definition: Convert.h:72
static DLLEXPORT Logger * Get()
Definition: Logger.cpp:106
ITERATORCALLBACK_RETURNTYPE FindUntilSpecificCharacter(IteratorFindUntilData *data, int character, int specialflags)

◆ GetPreviousCharacter()

DLLEXPORT int Leviathan::StringIterator::GetPreviousCharacter ( )

Gets the previous character.

Definition at line 82 of file StringIterator.cpp.

83 {
84  int tmpval = -1;
85  if(!DataIterator->GetPreviousCharacter(tmpval)) {
86  // Darn //
87  ITR_COREDEBUG("Failed to get previous character");
88  return 0;
89  }
90 
91  ITR_COREDEBUG("Peek back char: (" + Convert::CodePointToUtf8(tmpval) + ")");
92  return tmpval;
93 }
#define ITR_COREDEBUG(x)
static DLLEXPORT std::string CodePointToUtf8(int32_t codepoint)
Encodes a Unicode code point as an UTF8 string.
Definition: Convert.cpp:137
virtual bool GetPreviousCharacter(int &receiver)=0
Gets the previous character code point.

◆ GetStringInBracketsRecursive()

template<class RStrType >
std::unique_ptr<RStrType> Leviathan::StringIterator::GetStringInBracketsRecursive ( int  specialflags = 0)
inline

Gets characters inside brackets.

This function will skip until it finds a a left bracket '[' and then returns the content inside keeping track of the number of '[' and ']' characters encountered and returns once the top level brackets close

Note
Empty brackets "[]" are considered invalid and return NULL
Returns
The string found or NULL

Definition at line 429 of file StringIterator.h.

430  {
431 
432  // Setup the result object //
433  IteratorNestingLevelData data;
434 
435  // Iterate with our getting function //
436  StartIterating(specialflags, &StringIterator::FindInMatchingParentheses, &data, '[',
437  ']', specialflags);
438 
439  // Create the substring from the result //
440  std::unique_ptr<RStrType> resultstr;
441 
442  // NULL if nothing found //
443  if(!data.Positions.Start || !data.Positions.End)
444  return nullptr;
445 
446  // Return the wanted part //
447  return GetSubstringFromIndexes<RStrType>(data.Positions.Start, data.Positions.End);
448  }
ITERATORCALLBACK_RETURNTYPE FindInMatchingParentheses(IteratorNestingLevelData *data, int left, int right, int specialflags)

◆ GetStringInQuotes()

template<class RStrType >
std::unique_ptr<RStrType> Leviathan::StringIterator::GetStringInQuotes ( QUOTETYPE  quotes,
int  specialflags = 0 
)
inline

Gets the next string in quotes.

This function will skip until it finds a quote (either " or ' specified by quotes) and then returns the content inside

Returns
The string found or NULL

Definition at line 180 of file StringIterator.h.

181  {
182  // Setup the result object //
183  IteratorPositionData data;
184 
185  // Iterate with our getting function //
186  StartIterating(
187  specialflags, &StringIterator::FindFirstQuotedString, &data, quotes, specialflags);
188 
189  // Create the substring from the result //
190  std::unique_ptr<RStrType> resultstr;
191 
192  // NULL if nothing found //
193  if(!data.Positions.Start || !data.Positions.End)
194  return nullptr;
195 
196  // Return the wanted part //
197  return GetSubstringFromIndexes<RStrType>(data.Positions.Start, data.Positions.End);
198  }
ITERATORCALLBACK_RETURNTYPE FindFirstQuotedString(IteratorPositionData *data, QUOTETYPE quotes, int specialflags)

◆ GetSubstringFromIndexes()

template<class STRSType >
std::unique_ptr<STRSType> Leviathan::StringIterator::GetSubstringFromIndexes ( size_t  firstcharacter,
size_t  lastcharacter 
) const
inline

Returns substring from the wanted indexes.

Definition at line 605 of file StringIterator.h.

607  {
608  // Don't want to do anything if no string //
609  if(!DataIterator)
610  return nullptr;
611 
612  // Return a substring from our data source //
613  std::unique_ptr<STRSType> returnval(new STRSType());
614 
615  if(DataIterator->ReturnSubString(firstcharacter, lastcharacter, *returnval)) {
616 
617  return returnval;
618  }
619 
620  // It failed for some reason //
621  return nullptr;
622  }
virtual DLLEXPORT bool ReturnSubString(size_t startpos, size_t endpos, std::string &receiver)

◆ GetUntilCharacterSequence()

template<class RStrType >
std::unique_ptr<RStrType> Leviathan::StringIterator::GetUntilCharacterSequence ( const RStrType &  findstr,
int  specialflags = 0 
)
inline

Gets all characters until a sequence is matched.

Returns
The string found or NULL
Bug:
Finding until an UTF-8 sequence doesn't work, the findstr parameter should be a StringDataIterator for it to work

Definition at line 394 of file StringIterator.h.

396  {
397  // Setup the result object //
398  IteratorUntilSequenceData<RStrType> data(findstr);
399 
400  // Iterate with our getting function //
401  StartIterating(
402  specialflags, &StringIterator::FindUntilSequence<RStrType>, &data, specialflags);
403 
404  // Check for validity //
405  if(!data.Positions.Start) {
406  // Nothing found //
407  return nullptr;
408  }
409 
410  // This only happens when the string ends with a partial match //
411  // Example: look for "this", string is like this: my super nice th
412  if(!data.Positions.End) {
413  // Set to end of string //
414  data.Positions.End = GetLastValidCharIndex();
415  }
416 
417  // Return the wanted part //
418  return GetSubstringFromIndexes<RStrType>(data.Positions.Start, data.Positions.End);
419  }
size_t GetLastValidCharIndex() const
Returns the last valid index on the iterator.

◆ GetUntilEnd()

template<class RStrType >
std::unique_ptr<RStrType> Leviathan::StringIterator::GetUntilEnd ( )
inline

Gets all characters until the end.

Note
This does not advance the iterator so this object can still be used after this
Returns
The string found or NULL if the read position is invalid

Definition at line 297 of file StringIterator.h.

298  {
299 
300  // Just return from here to the last character //
301  return GetSubstringFromIndexes<RStrType>(GetPosition(), GetLastValidCharIndex());
302  }
size_t GetLastValidCharIndex() const
Returns the last valid index on the iterator.
size_t GetPosition()
Returns the current reading position.

◆ GetUntilEqualityAssignment()

template<class RStrType >
std::unique_ptr<RStrType> Leviathan::StringIterator::GetUntilEqualityAssignment ( EQUALITYCHARACTER  stopcase,
int  specialflags = 0 
)
inline

Gets the string that is before the equality assignment.

This function will read until either : or = is encountered specified by stopcase

Returns
The string found or NULL

Definition at line 267 of file StringIterator.h.

269  {
270  // Setup the result object //
271  IteratorAssignmentData data;
272 
273  // Iterate with our getting function //
274  StartIterating(
275  specialflags, &StringIterator::FindUntilEquality, &data, stopcase, specialflags);
276 
277  // Check for validity //
278  if(!data.Positions.Start || data.SeparatorFound == false) {
279  // nothing found //
280  return nullptr;
281  }
282 
283  if(!data.Positions.End) {
284  // Set to start, this only happens if there is just one character //
285  data.Positions.End = data.Positions.Start;
286  }
287 
288  // Return the wanted part //
289  return GetSubstringFromIndexes<RStrType>(data.Positions.Start, data.Positions.End);
290  }
ITERATORCALLBACK_RETURNTYPE FindUntilEquality(IteratorAssignmentData *data, EQUALITYCHARACTER equality, int specialflags)

◆ GetUntilLineEnd()

template<class RStrType >
std::unique_ptr<RStrType> Leviathan::StringIterator::GetUntilLineEnd ( )
inline

Gets all characters until a line end.

This function will read until a new line character and end after it

Returns
The string found or NULL

Definition at line 309 of file StringIterator.h.

310  {
311 
312  // Setup the result object //
313  IteratorFindUntilData data;
314 
315  // Iterate with our getting function //
316  StartIterating(0, &StringIterator::FindUntilNewLine, &data);
317 
318  // Check for validity //
319  if(!data.Positions.Start) {
320  // Nothing found //
321  return nullptr;
322  }
323 
324  if(!data.Positions.End) {
325  // Set to end of string //
326  data.Positions.End = GetLastValidCharIndex();
327  }
328 
329  // Return the wanted part //
330  return GetSubstringFromIndexes<RStrType>(data.Positions.Start, data.Positions.End);
331  }
size_t GetLastValidCharIndex() const
Returns the last valid index on the iterator.
ITERATORCALLBACK_RETURNTYPE FindUntilNewLine(IteratorFindUntilData *data)

◆ GetUntilNextCharacterOrAll()

template<class RStrType >
std::unique_ptr<RStrType> Leviathan::StringIterator::GetUntilNextCharacterOrAll ( int  charactertolookfor,
int  specialflags = 0 
)
inline

Gets characters until a character or all remaining characters.

This function will read until charactertolookfor and return the string without charactertolookfor, or if not found until the end

Parameters
charactertolookforThe code point to look for
Returns
The string found or NULL if there are no valid characters left
See also
GetUntilNextCharacterOrAll GetUntilEnd

Definition at line 368 of file StringIterator.h.

370  {
371  auto data = GetPositionsUntilACharacter(charactertolookfor, specialflags);
372 
373  if(!data.Positions.Start || !data.Positions.End) {
374  // return empty string //
375  return nullptr;
376  }
377 
378  // Return all if not found //
379  if(!data.FoundEnd &&
380  (!data.NewLineBreak || !(specialflags & SPECIAL_ITERATOR_ONNEWLINE_STOP))) {
381  return GetSubstringFromIndexes<RStrType>(
382  data.Positions.Start, GetLastValidCharIndex());
383  }
384 
385  // Return the wanted part //
386  return GetSubstringFromIndexes<RStrType>(data.Positions.Start, data.Positions.End);
387  }
size_t GetLastValidCharIndex() const
Returns the last valid index on the iterator.
IteratorFindUntilData GetPositionsUntilACharacter(int character, int specialflags=0)
Gets the position of the current character and the specified character.

◆ GetUntilNextCharacterOrNothing()

template<class RStrType >
std::unique_ptr<RStrType> Leviathan::StringIterator::GetUntilNextCharacterOrNothing ( int  charactertolookfor,
int  specialflags = 0 
)
inline

Gets characters until a character or nothing if the specified character is not found.

This function will read until charactertolookfor and return the string without charactertolookfor, or if not found nothing

Parameters
charactertolookforThe code point to look for
Returns
The string found or NULL
See also
GetUntilNextCharacterOrAll

Definition at line 344 of file StringIterator.h.

346  {
347 
348  auto data = GetPositionsUntilACharacter(charactertolookfor, specialflags);
349 
350  // Check was the end found //
351  if(!data.FoundEnd || !data.Positions.Start) {
352  // not found the ending character //
353  return nullptr;
354  }
355 
356  // Return the wanted part //
357  return GetSubstringFromIndexes<RStrType>(data.Positions.Start, data.Positions.End);
358  }
IteratorFindUntilData GetPositionsUntilACharacter(int character, int specialflags=0)
Gets the position of the current character and the specified character.

◆ IsAtNewLine()

bool Leviathan::StringIterator::IsAtNewLine ( )
inline

Returns true if current character is a new line.

Definition at line 535 of file StringIterator.h.

536  {
537 
538  // Ignore new lines if '\' is put before them
539  if(CurrentFlags & ITERATORFLAG_SET_IGNORE_SPECIAL)
540  return false;
541 
543  }
static bool IsLineTerminator(int32_t codepoint)
\ is found, next special character will be ignored
int GetCharacter(size_t forward=0)
Gets the character in the position current + forward.

◆ IsInsideComment()

bool Leviathan::StringIterator::IsInsideComment ( )
inline

Definition at line 597 of file StringIterator.h.

598  {
599 
600  return CurrentFlags & ITERATORFLAG_SET_INSIDE_CCOMMENT;
601  }
Set when inside a /* comment.

◆ IsInsideString()

bool Leviathan::StringIterator::IsInsideString ( )
inline

Definition at line 591 of file StringIterator.h.

592  {
593 
594  return CurrentFlags & ITERATORFLAG_SET_INSIDE_STRING;
595  }
Iterator is currently inside a string.

◆ IsOutOfBounds()

bool Leviathan::StringIterator::IsOutOfBounds ( )
inline

Returns true when the read position is valid.

Definition at line 584 of file StringIterator.h.

585  {
586 
587  return !DataIterator->IsPositionValid();
588  }
virtual bool IsPositionValid() const =0
Returns true when the iterator is still valid.

◆ MoveToNext()

bool Leviathan::StringIterator::MoveToNext ( )
inline

Skips the current character and moves to the next.

Returns
True when there is a valid character or false if the end has already been reached

Definition at line 558 of file StringIterator.h.

559  {
560 
561  DataIterator->MoveToNextCharacter();
562  bool valid = DataIterator->IsPositionValid();
563  // It's important to reset this //
564  CurrentStored = false;
565 
566  // We need to handle the flags on this position if we aren't on the first character //
567  if(valid && DataIterator->CurrentIteratorPosition() != 0) {
568 
569  ITR_COREDEBUG("Move to next");
570 
571  CheckActiveFlags();
572 
573  // check current character //
574  HandleSpecialCharacters();
575  }
576 
577  return valid;
578  }
virtual void MoveToNextCharacter()=0
Moves the iterator forward.
virtual size_t CurrentIteratorPosition() const =0
Gets the position of the iterator, for use with ReturnSubString and others.
#define ITR_COREDEBUG(x)
virtual bool IsPositionValid() const =0
Returns true when the iterator is still valid.

◆ ReInit() [1/5]

DLLEXPORT void StringIterator::ReInit ( std::unique_ptr< StringDataIterator > &&  iterator)

Changes the current iterator to the new iterator and goes to the beginning.

Definition at line 40 of file StringIterator.cpp.

41 {
42  // Remove the last iterator //
43  if(HandlesDelete) {
44 
45  SAFE_DELETE(DataIterator);
46  }
47 
48  ITR_COREDEBUG("ReInit")
49 
50  HandlesDelete = true;
51  DataIterator = iterator.release();
52 
53  // Reset everything //
54  CurrentCharacter = -1;
55  CurrentStored = false;
56 
57 
58  // Clear the flags //
59  CurrentFlags = 0;
60 }
#define ITR_COREDEBUG(x)
#define SAFE_DELETE(x)
Definition: Define.h:147

◆ ReInit() [2/5]

DLLEXPORT void Leviathan::StringIterator::ReInit ( const std::wstring &  text)

Helper function for ReInit for common string type.

Definition at line 62 of file StringIterator.cpp.

63 {
64  ReInit(std::make_unique<StringClassDataIterator<wstring>>(text));
65 }
Iterator for string types.
DLLEXPORT void ReInit(std::unique_ptr< StringDataIterator > &&iterator)
Changes the current iterator to the new iterator and goes to the beginning.

◆ ReInit() [3/5]

DLLEXPORT void Leviathan::StringIterator::ReInit ( const std::string &  text)

Helper function for ReInit for common string type.

Definition at line 67 of file StringIterator.cpp.

68 {
69  ReInit(std::make_unique<StringClassDataIterator<string>>(text));
70 }
Iterator for string types.
DLLEXPORT void ReInit(std::unique_ptr< StringDataIterator > &&iterator)
Changes the current iterator to the new iterator and goes to the beginning.

◆ ReInit() [4/5]

DLLEXPORT void Leviathan::StringIterator::ReInit ( const std::wstring *  text)

Helper function for ReInit for common string type.

Parameters
textPointer to a string that won't be deleted by this

Definition at line 72 of file StringIterator.cpp.

73 {
74  ReInit(std::make_unique<StringClassPointerIterator<wstring>>(text));
75 }
DLLEXPORT void ReInit(std::unique_ptr< StringDataIterator > &&iterator)
Changes the current iterator to the new iterator and goes to the beginning.
Iterator that doesn&#39;t hold own copy of a string.

◆ ReInit() [5/5]

DLLEXPORT void Leviathan::StringIterator::ReInit ( const std::string *  text)

Helper function for ReInit for common string type.

Parameters
textPointer to a string that won't be deleted by this

Definition at line 77 of file StringIterator.cpp.

78 {
79  ReInit(std::make_unique<StringClassPointerIterator<string>>(text));
80 }
DLLEXPORT void ReInit(std::unique_ptr< StringDataIterator > &&iterator)
Changes the current iterator to the new iterator and goes to the beginning.
Iterator that doesn&#39;t hold own copy of a string.

◆ SkipCharacters()

void Leviathan::StringIterator::SkipCharacters ( int  chartoskip,
int  additionalflag = 0,
int  specialflags = 0 
)
inline

Skips until chartoskip doesn't match the current character.

Parameters
chartoskipThe code point to skip
additionalflagFlag composing of UNNORMALCHARACTER_TYPE which defines additional things to skip
See also
SkipWhiteSpace

Definition at line 463 of file StringIterator.h.

464  {
465  IteratorCharacterData stufftoskip(chartoskip);
466 
467  // Iterate over the string skipping until hit something that doesn't need to be
468  // skipped
469  StartIterating(specialflags, &StringIterator::SkipSomething, stufftoskip,
470  additionalflag, specialflags);
471  }
ITERATORCALLBACK_RETURNTYPE SkipSomething(IteratorCharacterData &data, const int additionalskip, const int specialflags)

◆ SkipLineEnd()

DLLEXPORT void Leviathan::StringIterator::SkipLineEnd ( )

Skips characters until the line number changes.

Definition at line 95 of file StringIterator.cpp.

96 {
97  ITR_COREDEBUG("Skip line end");
98 
99  const auto current = GetCharacter(0);
100  const auto next = GetCharacter(1);
101 
102  // Move past the current new line //
103  MoveToNext();
104 
105  // Skip multi part new lines //
107  MoveToNext();
108 }
static bool IsLineTerminator(int32_t codepoint)
uint32_t next(octet_iterator &it, octet_iterator end)
Definition: checked.h:137
bool MoveToNext()
Skips the current character and moves to the next.
#define ITR_COREDEBUG(x)
int GetCharacter(size_t forward=0)
Gets the character in the position current + forward.

◆ SkipSomething()

ITERATORCALLBACK_RETURNTYPE Leviathan::StringIterator::SkipSomething ( IteratorCharacterData data,
const int  additionalskip,
const int  specialflags 
)
inlineprotected

Definition at line 1420 of file StringIterator.h.

1422  {
1423  if(specialflags & SPECIAL_ITERATOR_ONNEWLINE_STOP && IsAtNewLine()) {
1424  ITR_FUNCDEBUG("Stopping to new line");
1425 
1426  SkipLineEnd();
1428  }
1429 
1430  // We can probably always skip inside a comment //
1431  if((specialflags & SPECIAL_ITERATOR_HANDLECOMMENTS_ASSTRING) &&
1432  (CurrentFlags & ITERATORFLAG_SET_INSIDE_COMMENT)) {
1434  }
1435 
1436  // We can just return if we are inside a string //
1437  if(CurrentFlags & ITERATORFLAG_SET_INSIDE_STRING) {
1439  }
1440 
1441  // Check does the character match what is being skipped //
1442  int curchara = GetCharacter();
1443 
1444  if(additionalskip & UNNORMALCHARACTER_TYPE_LOWCODES) {
1445  if(curchara <= 32)
1447  }
1448 
1449  if(curchara == data.CharacterToUse) {
1450  // We want to skip it //
1452  }
1453 
1454  // didn't match to be skipped characters //
1456  }
int GetCharacter(size_t forward=0)
Gets the character in the position current + forward.
#define ITR_FUNCDEBUG(x)
DLLEXPORT void SkipLineEnd()
Skips characters until the line number changes.
Causes comments to be handled as whitespace/delimiting.
Iterator is currently inside a string.
bool IsAtNewLine()
Returns true if current character is a new line.

◆ SkipWhiteSpace()

void Leviathan::StringIterator::SkipWhiteSpace ( int  specialflags = 0)
inline

Skips until characters that are not whitespace are found.

See also
SkipCharacters

Definition at line 452 of file StringIterator.h.

453  {
454 
456  }
void SkipCharacters(int chartoskip, int additionalflag=0, int specialflags=0)
Skips until chartoskip doesn&#39;t match the current character.

The documentation for this class was generated from the following files: