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 129 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 14 of file StringIterator.cpp.

15  :
16  HandlesDelete(true), DataIterator(iterator.release())
17 {
18 
19 }

◆ StringIterator() [2/6]

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

Helper constructor for common string type.

Definition at line 28 of file StringIterator.cpp.

28  :
29  HandlesDelete(true),
30  DataIterator(new StringClassDataIterator<wstring>(text))
31 {
32 
33 }
Iterator for string types.

◆ StringIterator() [3/6]

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

Helper constructor for common string type.

Definition at line 21 of file StringIterator.cpp.

21  :
22  HandlesDelete(true),
23  DataIterator(new StringClassDataIterator<string>(text))
24 {
25 
26 }
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 35 of file StringIterator.cpp.

35  :
36  HandlesDelete(true),
37  DataIterator(new StringClassPointerIterator<wstring>(text))
38 {
39 
40 }
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 42 of file StringIterator.cpp.

42  :
43  HandlesDelete(true),
44  DataIterator(new StringClassPointerIterator<string>(text))
45 {
46 
47 }
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 9 of file StringIterator.cpp.

10 {
11 
12 }

◆ ~StringIterator()

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

Definition at line 49 of file StringIterator.cpp.

49  {
50  if(HandlesDelete){
51 
52  SAFE_DELETE(DataIterator);
53  }
54 }
#define SAFE_DELETE(x)
Definition: Define.h:116

Member Function Documentation

◆ FindFirstQuotedString()

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

Definition at line 1061 of file StringIterator.h.

1063  {
1064  bool TakeChar = true;
1065  bool End = false;
1066 
1067  if(specialflags & SPECIAL_ITERATOR_ONNEWLINE_STOP && IsAtNewLine()){
1068  ITR_FUNCDEBUG("Stopping to new line");
1069 
1070  if(data->Positions.Start){
1071  // Set the last character to two before this
1072  // (skip the current and " and end there)
1073  int previouscheck = GetPreviousCharacter();
1074 
1075  // Check do we need to go back 2 characters or just one //
1076  if((quotes == QUOTETYPE_BOTH && (previouscheck == '"' ||
1077  previouscheck == '\'')) ||
1078  (quotes == QUOTETYPE_DOUBLEQUOTES && previouscheck == '"') ||
1079  (quotes == QUOTETYPE_SINGLEQUOTES && previouscheck == '\''))
1080  {
1081  ITR_FUNCDEBUG("Going back over an extra quote character");
1082  data->Positions.End = GetPosition()-2;
1083  } else {
1084  data->Positions.End = GetPosition()-1;
1085  }
1086 
1087  ITR_FUNCDEBUG("Ending to new line, end is now: "+
1088  Convert::ToString(data->Positions.End));
1089  }
1090 
1091  SkipLineEnd();
1093  }
1094 
1095  int currentcharacter = GetCharacter();
1096 
1097  switch(quotes){
1098  case QUOTETYPE_BOTH:
1099  {
1100  if(CurrentFlags & ITERATORFLAG_SET_INSIDE_STRING){
1101  // check if we are on the quotes, because we don't want those //
1102  if(currentcharacter == '"' || currentcharacter == '\''){
1103  // if we aren't ignoring special disallow //
1104  if(!(CurrentFlags & ITERATORFLAG_SET_IGNORE_SPECIAL)){
1105  TakeChar = false;
1106  ITR_FUNCDEBUG("Found quote character");
1107  }
1108  }
1109 
1110  } else {
1111  End = true;
1112  ITR_FUNCDEBUG("Outside quotes");
1113  }
1114  }
1115  break;
1117  {
1118  if(CurrentFlags & ITERATORFLAG_SET_INSIDE_STRING_SINGLE){
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  }
1133  break;
1135  {
1136  if(CurrentFlags & ITERATORFLAG_SET_INSIDE_STRING_DOUBLE){
1137  // check if we are on the quotes, because we don't want those //
1138  if(currentcharacter == '"'){
1139  // if we aren't ignoring special disallow //
1140  if(!(CurrentFlags & ITERATORFLAG_SET_IGNORE_SPECIAL)){
1141  TakeChar = false;
1142  ITR_FUNCDEBUG("Found quote character");
1143  }
1144  }
1145 
1146  } else {
1147  End = true;
1148  ITR_FUNCDEBUG("Outside quotes");
1149  }
1150  }
1151  break;
1152  }
1153 
1154  // If we have found a character this is on the ending quote //
1155  if(!TakeChar && data->Positions.Start){
1156 
1157  // Set the last character to the one before this (skip the " and end there) //
1158  data->Positions.End = GetPosition() - 1;
1159  ITR_FUNCDEBUG("On ending quote, end is now: "+
1160  Convert::ToString(data->Positions.End));
1161  }
1162 
1163  if(End){
1164  // if we have found at least a character we can end this here //
1165  if(data->Positions.Start){
1166  // Set the last character to two before this
1167  // (skip the current and " and end there)
1168  data->Positions.End = GetPosition() - 2;
1169  ITR_FUNCDEBUG("Ending outside quotes, end is now: "+
1170  Convert::ToString(data->Positions));
1172  }
1173  } else if(TakeChar){
1174  // check is this first quoted character //
1175  if(!data->Positions.Start){
1176  // first position! //
1177  data->Positions.Start = GetPosition();
1178  ITR_FUNCDEBUG("First character found: "+
1179  Convert::ToString(data->Positions.Start));
1180 
1181  }
1182  }
1183 
1185  }
\ 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 1619 of file StringIterator.h.

1621  {
1622  // Ignore if ignoring special characters //
1623  if(!(CurrentFlags & ITERATORFLAG_SET_IGNORE_SPECIAL) &&
1624  !(CurrentFlags & ITERATORFLAG_SET_INSIDE_STRING))
1625  {
1626  if(specialflags & SPECIAL_ITERATOR_ONNEWLINE_STOP && IsAtNewLine()){
1627 
1628  // Invalid, always //
1630  }
1631 
1632  int currentcharacter = GetCharacter();
1633 
1634  // Nesting level starts //
1635  if(currentcharacter == left){
1636 
1637  ++data->NestingLevel;
1638 
1639  if(data->NestingLevel > 1){
1640 
1641  // There where multiple lefts in a row, like "[[[...]]]"
1642  goto isinsidevalidleftrightpair;
1643  }
1644 
1646  }
1647 
1648  // One nesting level is ending //
1649  if(currentcharacter == right){
1650 
1651  --data->NestingLevel;
1652 
1653  if(data->NestingLevel == 0){
1654 
1655  data->Positions.End = GetPosition() - 1;
1657  }
1658  }
1659  }
1660 
1661  isinsidevalidleftrightpair:
1662 
1663  if(!data->Positions.Start && data->NestingLevel > 0){
1664 
1665  data->Positions.Start = GetPosition();
1666  }
1667 
1669  }
\ 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 1187 of file StringIterator.h.

1189  {
1190  bool IsValid = true;
1191 
1192  if(specialflags & SPECIAL_ITERATOR_ONNEWLINE_STOP && IsAtNewLine()){
1193  ITR_FUNCDEBUG("Stopping to new line");
1194 
1195  if(data->Positions.Start){
1196  // ended //
1197  data->Positions.End = GetPosition() - 1;
1198  ITR_FUNCDEBUG("Ending to new line, end is now: "+
1199  Convert::ToString(data->Positions.End));
1200  }
1201 
1202  SkipLineEnd();
1204  }
1205 
1206  int currentcharacter = GetCharacter();
1207 
1208  // If set this is invalid inside comments //
1209  if((specialflags & SPECIAL_ITERATOR_HANDLECOMMENTS_ASSTRING) &&
1210  (CurrentFlags & ITERATORFLAG_SET_INSIDE_COMMENT))
1211  {
1212  IsValid = false;
1213  goto invalidcodelabelunnormalcharacter;
1214  }
1215 
1216  if((stopflags & UNNORMALCHARACTER_TYPE_LOWCODES ||
1218  && !(CurrentFlags & ITERATORFLAG_SET_INSIDE_STRING))
1219  {
1220  if(currentcharacter <= ' '){
1221  IsValid = false;
1222  goto invalidcodelabelunnormalcharacter;
1223  }
1224  }
1225 
1226  if(stopflags & UNNORMALCHARACTER_TYPE_NON_ASCII){
1227 
1228  if(CurrentFlags & ITERATORFLAG_SET_INSIDE_STRING || !(
1229  (currentcharacter >= '0' && currentcharacter <= '9') ||
1230  (currentcharacter >= 'A' && currentcharacter <= 'Z') ||
1231  (currentcharacter >= 'a' && currentcharacter <= 'z')))
1232  {
1233  IsValid = false;
1234  goto invalidcodelabelunnormalcharacter;
1235  }
1236  }
1237 
1239  !(CurrentFlags & ITERATORFLAG_SET_INSIDE_STRING)
1240  && !(CurrentFlags & ITERATORFLAG_SET_IGNORE_SPECIAL))
1241  {
1242  if(((currentcharacter <= '/' && currentcharacter >= '!') ||
1243  (currentcharacter <= '@' && currentcharacter >= ':')
1244  || (currentcharacter <= '`' && currentcharacter >= '[') ||
1245  (currentcharacter <= '~' && currentcharacter >= '{'))
1246  && !(currentcharacter == '_' || currentcharacter == '-'))
1247  {
1248  IsValid = false;
1249  goto invalidcodelabelunnormalcharacter;
1250  }
1251  }
1252 
1253  if(IsValid){
1254  // check is this first character //
1255  if(!data->Positions.Start){
1256  // first position! //
1257  data->Positions.Start = GetPosition();
1258  ITR_FUNCDEBUG("Started: "+Convert::ToString(data->Positions.Start));
1259  }
1260 
1261  } else {
1262 
1263  invalidcodelabelunnormalcharacter:
1264 
1265 
1266  // check for end //
1267  if(data->Positions.Start){
1268  // ended //
1269  data->Positions.End = GetPosition() - 1;
1270  ITR_FUNCDEBUG("End now: "+Convert::ToString(data->Positions.End));
1272  }
1273  }
1274 
1276  }
\ 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 1278 of file StringIterator.h.

1280  {
1281  // Check is the current element a part of a number //
1282 
1283  bool IsValid = false;
1284 
1285  if(specialflags & SPECIAL_ITERATOR_ONNEWLINE_STOP && IsAtNewLine()){
1286  ITR_FUNCDEBUG("Stopping to new line");
1287 
1288  if(data->Positions.Start){
1289  // ended //
1290  data->Positions.End = GetPosition() - 1;
1291  ITR_FUNCDEBUG("Ending to new line, end is now: "+
1292  Convert::ToString(data->Positions.End));
1293  }
1294 
1295  SkipLineEnd();
1297  }
1298 
1299  // Comments might be skipped //
1300  if(!(specialflags & SPECIAL_ITERATOR_HANDLECOMMENTS_ASSTRING) ||
1301  !(CurrentFlags & ITERATORFLAG_SET_INSIDE_COMMENT))
1302  {
1303 
1304  int currentcharacter = GetCharacter();
1305 
1306  if((currentcharacter >= 48) && (currentcharacter <= 57)){
1307  // Is a plain old digit //
1308  IsValid = true;
1309 
1310  } else {
1311  // Check is it a decimal separator (1 allowed)
1312  // or a negativity sign in front
1313  if(currentcharacter == '+' || currentcharacter == '-'){
1314 
1315  if((data->DigitsFound < 1) && (!data->NegativeFound)){
1316  IsValid = true;
1317  }
1318  data->NegativeFound = true;
1319  } else if (((currentcharacter == '.') &&
1320  ((decimal == DECIMALSEPARATORTYPE_DOT) ||
1321  (decimal == DECIMALSEPARATORTYPE_BOTH))) ||
1322  ((currentcharacter == ',') && ((decimal == DECIMALSEPARATORTYPE_COMMA) ||
1323  (decimal == DECIMALSEPARATORTYPE_BOTH))))
1324  {
1325  if((!data->DecimalFound) && (data->DigitsFound > 0)){
1326  IsValid = true;
1327  data->DecimalFound = true;
1328  }
1329  }
1330  }
1331  } else {
1332  ITR_FUNCDEBUG("Ignoring inside a comment");
1333  }
1334 
1335  if(IsValid){
1336  // check is this first digit //
1337  data->DigitsFound++;
1338  if(!data->Positions.Start){
1339  // first position! //
1340 
1341  data->Positions.Start = GetPosition();
1342  ITR_FUNCDEBUG("Data started: "+Convert::ToString(data->Positions.Start));
1343  }
1344 
1345  } else {
1346  // check for end //
1347  if(data->Positions.Start){
1348  // ended //
1349  data->Positions.End = GetPosition() - 1;
1350  ITR_FUNCDEBUG("End now: "+Convert::ToString(data->Positions.End));
1352  }
1353 
1354  }
1356  }
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 1358 of file StringIterator.h.

1360  {
1361  // check is current element a valid element //
1362  bool IsValid = true;
1363  bool IsStop = false;
1364 
1365  if(specialflags & SPECIAL_ITERATOR_ONNEWLINE_STOP && IsAtNewLine()){
1366  ITR_FUNCDEBUG("Stopping to new line");
1367 
1368  SkipLineEnd();
1370  }
1371 
1372  // Comments cannot be part of this //
1373  if((specialflags & SPECIAL_ITERATOR_HANDLECOMMENTS_ASSTRING) &&
1374  (CurrentFlags & ITERATORFLAG_SET_INSIDE_COMMENT))
1375  {
1376  // Not valid inside a comment //
1377  ITR_FUNCDEBUG("Comment skipped");
1378  IsValid = false;
1379 
1380  } else {
1381 
1382  int charvalue = GetCharacter();
1383 
1384  // Skip if this is a space //
1385  if(charvalue < 33){
1386  // Not allowed in a name //
1387  ITR_FUNCDEBUG("Whitespace skipped");
1388  IsValid = false;
1389  }
1390 
1391  if(equality == EQUALITYCHARACTER_TYPE_ALL){
1392  // check for all possible value separators //
1393  if(charvalue == '=' || charvalue == ':'){
1394 
1395  if(!(CurrentFlags & ITERATORFLAG_SET_IGNORE_SPECIAL)){
1396  // If ignored don't stop //
1397  ITR_FUNCDEBUG("Found = or :");
1398  IsStop = true;
1399  }
1400  }
1401  } else if(equality == EQUALITYCHARACTER_TYPE_EQUALITY){
1402  // Check for an equality sign //
1403  if(charvalue == '='){
1404  if(!(CurrentFlags & ITERATORFLAG_SET_IGNORE_SPECIAL)){
1405  ITR_FUNCDEBUG("Found =");
1406  IsStop = true;
1407  }
1408  }
1409  } else if (equality == EQUALITYCHARACTER_TYPE_DOUBLEDOTSTYLE){
1410  // Check does it match the characters //
1411  if(charvalue == ':'){
1412  if(!(CurrentFlags & ITERATORFLAG_SET_IGNORE_SPECIAL)){
1413  ITR_FUNCDEBUG("Found :");
1414  IsStop = true;
1415  }
1416  }
1417  }
1418  }
1419 
1420  if(!IsStop){
1421  // end if end already found //
1422  if(data->SeparatorFound){
1423  ITR_FUNCDEBUG("Found stop");
1425  }
1426  } else {
1427  data->SeparatorFound = true;
1428  IsValid = false;
1429  }
1430 
1431  if(IsValid){
1432  // Check is this the first character //
1433  if(!data->Positions.Start){
1434  // first position! //
1435  data->Positions.Start = GetPosition();
1436  ITR_FUNCDEBUG("Data started: "+Convert::ToString(data->Positions.Start));
1437 
1438  } else {
1439  // Set end to this valid character //
1440  data->Positions.End = GetPosition();
1441  ITR_FUNCDEBUG("End now: "+Convert::ToString(data->Positions.End));
1442  }
1443  }
1444 
1445 
1447  }
\ 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 1579 of file StringIterator.h.

1581  {
1582  // Continue if the current character is a new line character //
1583 
1584  // All line separator characters should be here //
1585  if(IsAtNewLine()){
1586 
1587  if(!data->FoundEnd){
1588  // Ignore the first new line //
1589  data->FoundEnd = true;
1590  ITR_FUNCDEBUG("Ignoring first newline character");
1591  goto positionisvalidlabelstringiteratorfindnewline;
1592  }
1593 
1594  // This is a new line character //
1595  ITR_FUNCDEBUG("Found newline character");
1596 
1597  // End before this character //
1598  data->Positions.End = GetPosition() - 1;
1599  ITR_FUNCDEBUG("Ending here: "+Convert::ToString(data->Positions));
1600 
1601  SkipLineEnd();
1603  }
1604 
1605  positionisvalidlabelstringiteratorfindnewline:
1606 
1607  // Set position //
1608  if(!data->Positions.Start){
1609 
1610  // End before this character //
1611  data->Positions.Start = GetPosition();
1612  data->FoundEnd = true;
1613  ITR_FUNCDEBUG("Data started: "+Convert::ToString(data->Positions));
1614  }
1615 
1617  }
#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 1674 of file StringIterator.h.

1676  {
1677  // First check if this is a line end //
1678  int curcharacter = GetCharacter();
1679 
1680  if(specialflags & SPECIAL_ITERATOR_ONNEWLINE_STOP && IsAtNewLine()){
1681 
1682  // Set the end to one before this, if found any //
1683  if(data->Positions.Start){
1684 
1685  data->Positions.End = GetPosition() - 1;
1686  }
1687 
1688  SkipLineEnd();
1690  }
1691 
1692  // We may not be inside strings nor comments for checking //
1693  if(!(CurrentFlags & ITERATORFLAG_SET_INSIDE_STRING) &&
1694  (!(CurrentFlags & ITERATORFLAG_SET_INSIDE_COMMENT) ||
1695  !(specialflags & SPECIAL_ITERATOR_HANDLECOMMENTS_ASSTRING)))
1696  {
1697  // Check do we match the current position //
1698  if(curcharacter == data->StringToMatch[data->CurMatchedIndex]){
1699 
1700  // Found a matching character //
1701 
1702  // Move to next match position and don't yet verify if this is a valid
1703  // character
1704  ++data->CurMatchedIndex;
1705 
1706  if(data->CurMatchedIndex >= data->StringToMatch.size()){
1707 
1708  // End found //
1710  }
1711 
1713 
1714  }
1715 
1716  }
1717 
1718  // Go back to beginning of matching //
1719  data->CurMatchedIndex = 0;
1720 
1721  // All is fine //
1722  if(!data->Positions.Start){
1723 
1724  data->Positions.Start = GetPosition();
1725  data->Positions.End = data->Positions.Start;
1726  } else {
1727 
1728  // This might be poisonous to performance, but this gets the job done //
1729  data->Positions.End = GetPosition();
1730  }
1731 
1733  }
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 1489 of file StringIterator.h.

1491  {
1492  // Can this character be added //
1493  bool ValidChar = true;
1494 
1495  if(specialflags & SPECIAL_ITERATOR_ONNEWLINE_STOP && IsAtNewLine()){
1496  ITR_FUNCDEBUG("Stopping to new line");
1497 
1498  if(data->Positions.Start){
1499  // This should be fine to get here //
1500  data->Positions.End = GetPosition() - 1;
1501  ITR_FUNCDEBUG("Ending to new line, end is now: "+
1502  Convert::ToString(data->Positions.End));
1503  }
1504 
1505  // Make sure to not return until end of the whole string //
1506  data->NewLineBreak = true;
1507 
1508  SkipLineEnd();
1510  }
1511 
1512  int tmpchara = GetCharacter();
1513 
1514  // We can just continue if we are inside a string //
1515  if(!(CurrentFlags & ITERATORFLAG_SET_INSIDE_STRING) &&
1516  !((specialflags & SPECIAL_ITERATOR_HANDLECOMMENTS_ASSTRING)
1517  && (CurrentFlags & ITERATORFLAG_SET_INSIDE_COMMENT)))
1518  {
1519  // Check did we encounter stop character //
1520  #ifdef ALLOW_DEBUG
1521  if (DebugMode) {
1522 
1523  std::string value = "Trying to match: ";
1524  utf8::append(tmpchara, std::back_inserter(value));
1525  value += "==" + Convert::ToString(tmpchara);
1526 
1527  Logger::Get()->Write("Iterator: procfunc: " + value); \
1528  }
1529  #endif // ALLOW_DEBUG
1530 
1531  if(tmpchara == character){
1532  // Skip if ignoring special characters //
1533  if(!(CurrentFlags & ITERATORFLAG_SET_IGNORE_SPECIAL)){
1534  // Not valid character //
1535  ValidChar = false;
1536  ITR_FUNCDEBUG("Found match");
1537  // We must have started to encounter the stop character //
1538  if(data->Positions.Start){
1539  // We encountered the stop character //
1540  data->FoundEnd = true;
1541  ITR_FUNCDEBUG("Encountered end");
1542  }
1543  }
1544  }
1545  } else {
1546  #ifdef ALLOW_DEBUG
1547  if((CurrentFlags & ITERATORFLAG_SET_INSIDE_STRING)){
1548  ITR_FUNCDEBUG("Ignoring inside string");
1549  }
1550  if((specialflags & SPECIAL_ITERATOR_HANDLECOMMENTS_ASSTRING) &&
1551  (CurrentFlags & ITERATORFLAG_SET_INSIDE_COMMENT))
1552  {
1553  ITR_FUNCDEBUG("Ignoring inside comment");
1554  }
1555  #endif // _DEBUG
1556  }
1557 
1558  if(ValidChar){
1559  // valid character set start if not already set //
1560  if(!data->Positions.Start){
1561  data->Positions.Start = GetPosition();
1562  data->Positions.End = data->Positions.Start;
1563  ITR_FUNCDEBUG("Data started: "+Convert::ToString(data->Positions.Start));
1564  }
1566  }
1567  // let's stop if we have found something //
1568  if(data->Positions.Start){
1569  // This should be fine to get here //
1570  data->Positions.End = GetPosition() - 1;
1571  ITR_FUNCDEBUG("Ending here: "+Convert::ToString(data->Positions.End));
1573  }
1574 
1575  // haven't found anything, we'll need to find something //
1577  }
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 504 of file StringIterator.h.

504  {
505 
506  // Special case for current character //
507  if(!forward){
508 
509  if(!CurrentStored){
510 
511  if(!DataIterator->GetNextCharCode(CurrentCharacter, 0)){
512 
513  // Invalid position //
514  return -1;
515  }
516 
517  CurrentStored = true;
518 
519  ITR_COREDEBUG("Current char: (" +
520  Convert::CodePointToUtf8(CurrentCharacter) + ")");
521  }
522 
523  return CurrentCharacter;
524  }
525 
526  // Get the character from our iterator and store it to a temporary value
527  // and then return it
528  int tmpval = -1;
529  DataIterator->GetNextCharCode(tmpval, forward);
530 
531  ITR_COREDEBUG("Peek forward char: (" + Convert::CodePointToUtf8(tmpval) + ")");
532 
533  return tmpval;
534  }
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 498 of file StringIterator.h.

498  {
499 
500  return DataIterator->GetCurrentLineNumber();
501  }
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 550 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 236 of file StringIterator.h.

238  {
239 
240  // Setup the result object //
241  IteratorPositionData data;
242 
243  // Iterate with our getting function //
244  StartIterating(specialflags, &StringIterator::FindNextNormalCharacterString,
245  &data, 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 203 of file StringIterator.h.

205  {
206 
207  // Setup the result object //
208  IteratorNumberFindData data;
209 
210  // iterate over the string getting the proper part //
211  // Iterate with our getting function //
212  StartIterating(specialflags, &StringIterator::FindNextNumber,
213  &data, decimal, specialflags);
214 
215  // Check for nothing found //
216  if(!data.Positions.Start){
217  return nullptr;
218  }
219 
220  // create substring of the wanted part //
221 
222 
223  // Make sure end is fine //
224  if(!data.Positions.End)
225  data.Positions.End = GetLastValidCharIndex();
226 
227  // Return the wanted part //
228  return GetSubstringFromIndexes<RStrType>(data.Positions.Start, data.Positions.End);
229  }
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 492 of file StringIterator.h.

492  {
493 
494  return DataIterator->CurrentIteratorPosition();
495  }
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 622 of file StringIterator.h.

624  {
625  // Setup the result object //
626  IteratorFindUntilData data;
627 
628  // Iterate with our getting function //
629  StartIterating(specialflags, &StringIterator::FindUntilSpecificCharacter,
630  &data, character, specialflags);
631 
632  #ifdef ITERATOR_ALLOW_DEBUG
633  if(DebugMode){
634  Logger::Get()->Write("Iterator: find GetPositionsUntilACharacter, positions: " +
635  Convert::ToString(data.Positions) + ", found: "+
636  Convert::ToString(data.FoundEnd));
637  }
638  #endif // _DEBUG
639 
640  return data;
641  }
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 94 of file StringIterator.cpp.

94  {
95  int tmpval = -1;
96  if(!DataIterator->GetPreviousCharacter(tmpval)){
97  // Darn //
98  ITR_COREDEBUG("Failed to get previous character");
99  return 0;
100  }
101 
102  ITR_COREDEBUG("Peek back char: (" + Convert::CodePointToUtf8(tmpval) + ")");
103  return tmpval;
104 }
#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 434 of file StringIterator.h.

434  {
435 
436  // Setup the result object //
437  IteratorNestingLevelData data;
438 
439  // Iterate with our getting function //
440  StartIterating(specialflags, &StringIterator::FindInMatchingParentheses,
441  &data, '[', ']', specialflags);
442 
443  // Create the substring from the result //
444  std::unique_ptr<RStrType> resultstr;
445 
446  // NULL if nothing found //
447  if(!data.Positions.Start || !data.Positions.End)
448  return nullptr;
449 
450  // Return the wanted part //
451  return GetSubstringFromIndexes<RStrType>(data.Positions.Start, data.Positions.End);
452  }
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 174 of file StringIterator.h.

176  {
177 
178  // Setup the result object //
179  IteratorPositionData data;
180 
181  // Iterate with our getting function //
182  StartIterating(specialflags, &StringIterator::FindFirstQuotedString,
183  &data, quotes, specialflags);
184 
185  // Create the substring from the result //
186  std::unique_ptr<RStrType> resultstr;
187 
188  // NULL if nothing found //
189  if(!data.Positions.Start || !data.Positions.End)
190  return nullptr;
191 
192  // Return the wanted part //
193  return GetSubstringFromIndexes<RStrType>(data.Positions.Start, data.Positions.End);
194  }
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 601 of file StringIterator.h.

603  {
604  // Don't want to do anything if no string //
605  if(!DataIterator)
606  return nullptr;
607 
608  // Return a substring from our data source //
609  std::unique_ptr<STRSType> returnval(new STRSType());
610 
611  if(DataIterator->ReturnSubString(firstcharacter, lastcharacter, *returnval)){
612 
613  return returnval;
614  }
615 
616  // It failed for some reason //
617  return nullptr;
618  }
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 398 of file StringIterator.h.

400  {
401 
402  // Setup the result object //
403  IteratorUntilSequenceData<RStrType> data(findstr);
404 
405  // Iterate with our getting function //
406  StartIterating(specialflags, &StringIterator::FindUntilSequence<RStrType>,
407  &data, specialflags);
408 
409  // Check for validity //
410  if(!data.Positions.Start){
411  // Nothing found //
412  return nullptr;
413  }
414 
415  // This only happens when the string ends with a partial match //
416  // Example: look for "this", string is like this: my super nice th
417  if(!data.Positions.End){
418  // Set to end of string //
419  data.Positions.End = GetLastValidCharIndex();
420  }
421 
422  // Return the wanted part //
423  return GetSubstringFromIndexes<RStrType>(data.Positions.Start, data.Positions.End);
424  }
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 300 of file StringIterator.h.

300  {
301 
302  // Just return from here to the last character //
303  return GetSubstringFromIndexes<RStrType>(GetPosition(), GetLastValidCharIndex());
304  }
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 
271  // Setup the result object //
272  IteratorAssignmentData data;
273 
274  // Iterate with our getting function //
275  StartIterating(specialflags, &StringIterator::FindUntilEquality,
276  &data, stopcase, specialflags);
277 
278  // Check for validity //
279  if(!data.Positions.Start || data.Positions.Start == data.Positions.End ||
280  data.SeparatorFound == false)
281  {
282  // nothing found //
283  return nullptr;
284  }
285 
286  if(!data.Positions.End){
287  // Set to start, this only happens if there is just one character //
288  data.Positions.End = data.Positions.Start;
289  }
290 
291  // Return the wanted part //
292  return GetSubstringFromIndexes<RStrType>(data.Positions.Start, data.Positions.End);
293  }
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 311 of file StringIterator.h.

311  {
312 
313  // Setup the result object //
314  IteratorFindUntilData data;
315 
316  // Iterate with our getting function //
317  StartIterating(0, &StringIterator::FindUntilNewLine, &data);
318 
319  // Check for validity //
320  if(!data.Positions.Start){
321  // Nothing found //
322  return nullptr;
323  }
324 
325  if(!data.Positions.End){
326  // Set to end of string //
327  data.Positions.End = GetLastValidCharIndex();
328  }
329 
330  // Return the wanted part //
331  return GetSubstringFromIndexes<RStrType>(data.Positions.Start, data.Positions.End);
332  }
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 369 of file StringIterator.h.

371  {
372 
373  auto data = GetPositionsUntilACharacter(charactertolookfor, specialflags);
374 
375  if(!data.Positions.Start || !data.Positions.End){
376  // return empty string //
377  return nullptr;
378  }
379 
380  // Return all if not found //
381  if(!data.FoundEnd && (!data.NewLineBreak ||
382  !(specialflags & SPECIAL_ITERATOR_ONNEWLINE_STOP)))
383  {
384 
385  return GetSubstringFromIndexes<RStrType>(data.Positions.Start,
387  }
388 
389  // Return the wanted part //
390  return GetSubstringFromIndexes<RStrType>(data.Positions.Start, data.Positions.End);
391  }
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 345 of file StringIterator.h.

347  {
348 
349  auto data = GetPositionsUntilACharacter(charactertolookfor, specialflags);
350 
351  // Check was the end found //
352  if(!data.FoundEnd || !data.Positions.Start){
353  // not found the ending character //
354  return nullptr;
355  }
356 
357  // Return the wanted part //
358  return GetSubstringFromIndexes<RStrType>(data.Positions.Start, data.Positions.End);
359  }
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 537 of file StringIterator.h.

537  {
538 
539  // Ignore new lines if '\' is put before them
540  if (CurrentFlags & ITERATORFLAG_SET_IGNORE_SPECIAL)
541  return false;
542 
544  }
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 594 of file StringIterator.h.

594  {
595 
596  return CurrentFlags & ITERATORFLAG_SET_INSIDE_CCOMMENT;
597  }
Set when inside a /* comment.

◆ IsInsideString()

bool Leviathan::StringIterator::IsInsideString ( )
inline

Definition at line 589 of file StringIterator.h.

589  {
590 
591  return CurrentFlags & ITERATORFLAG_SET_INSIDE_STRING;
592  }
Iterator is currently inside a string.

◆ IsOutOfBounds()

bool Leviathan::StringIterator::IsOutOfBounds ( )
inline

Returns true when the read position is valid.

Definition at line 583 of file StringIterator.h.

583  {
584 
585  return !DataIterator->IsPositionValid();
586  }
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.

558  {
559 
560  DataIterator->MoveToNextCharacter();
561  bool valid = DataIterator->IsPositionValid();
562  // It's important to reset this //
563  CurrentStored = false;
564 
565  // We need to handle the flags on this position if we aren't on the first character //
566  if(valid && DataIterator->CurrentIteratorPosition() != 0){
567 
568  ITR_COREDEBUG("Move to next");
569 
570  CheckActiveFlags();
571 
572  // check current character //
573  HandleSpecialCharacters();
574  }
575 
576  return valid;
577  }
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 56 of file StringIterator.cpp.

56  {
57 
58  // Remove the last iterator //
59  if(HandlesDelete){
60 
61  SAFE_DELETE(DataIterator);
62  }
63 
64  ITR_COREDEBUG("ReInit")
65 
66  HandlesDelete = true;
67  DataIterator = iterator.release();
68 
69  // Reset everything //
70  CurrentCharacter = -1;
71  CurrentStored = false;
72 
73 
74  // Clear the flags //
75  CurrentFlags = 0;
76 }
#define ITR_COREDEBUG(x)
#define SAFE_DELETE(x)
Definition: Define.h:116

◆ ReInit() [2/5]

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

Helper function for ReInit for common string type.

Definition at line 78 of file StringIterator.cpp.

78  {
79  ReInit(std::make_unique<StringClassDataIterator<wstring>>(text));
80 }
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 82 of file StringIterator.cpp.

82  {
83  ReInit(std::make_unique<StringClassDataIterator<string>>(text));
84 }
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 86 of file StringIterator.cpp.

86  {
87  ReInit(std::make_unique<StringClassPointerIterator<wstring>>(text));
88 }
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 90 of file StringIterator.cpp.

90  {
91  ReInit(std::make_unique<StringClassPointerIterator<string>>(text));
92 }
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 466 of file StringIterator.h.

468  {
469 
470  IteratorCharacterData stufftoskip(chartoskip);
471 
472  // Iterate over the string skipping until hit something that doesn't need to be
473  // skipped
474  StartIterating(specialflags, &StringIterator::SkipSomething,
475  stufftoskip, additionalflag, specialflags);
476  }
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 106 of file StringIterator.cpp.

106  {
107 
108  ITR_COREDEBUG("Skip line end");
109 
110  const auto current = GetCharacter(0);
111  const auto next = GetCharacter(1);
112 
113  // Move past the current new line //
114  MoveToNext();
115 
116  // Skip multi part new lines //
118  MoveToNext();
119 
120 }
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 1449 of file StringIterator.h.

1451  {
1452  if(specialflags & SPECIAL_ITERATOR_ONNEWLINE_STOP && IsAtNewLine()){
1453  ITR_FUNCDEBUG("Stopping to new line");
1454 
1455  SkipLineEnd();
1457  }
1458 
1459  // We can probably always skip inside a comment //
1460  if((specialflags & SPECIAL_ITERATOR_HANDLECOMMENTS_ASSTRING) &&
1461  (CurrentFlags & ITERATORFLAG_SET_INSIDE_COMMENT))
1462  {
1463 
1465  }
1466 
1467  // We can just return if we are inside a string //
1468  if(CurrentFlags & ITERATORFLAG_SET_INSIDE_STRING){
1470  }
1471 
1472  // Check does the character match what is being skipped //
1473  int curchara = GetCharacter();
1474 
1475  if(additionalskip & UNNORMALCHARACTER_TYPE_LOWCODES){
1476  if(curchara <= 32)
1478  }
1479 
1480  if(curchara == data.CharacterToUse){
1481  // We want to skip it //
1483  }
1484 
1485  // didn't match to be skipped characters //
1487  }
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 456 of file StringIterator.h.

456  {
457 
459  }
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: