Leviathan  0.8.0.0
Leviathan game engine
StringIterator.cpp
Go to the documentation of this file.
1 // ------------------------------------ //
2 #include "StringIterator.h"
3 
4 #include "utf8/checked.h"
5 using namespace Leviathan;
6 using namespace std;
7 // ------------------------------------ //
9 
11  std::unique_ptr<StringDataIterator>&& iterator) :
12  HandlesDelete(true),
13  DataIterator(iterator.release())
14 {}
15 
17  HandlesDelete(true), DataIterator(new StringClassDataIterator<string>(text))
18 {}
19 
21  HandlesDelete(true), DataIterator(new StringClassDataIterator<wstring>(text))
22 {}
23 
25  HandlesDelete(true), DataIterator(new StringClassPointerIterator<wstring>(text))
26 {}
27 
29  HandlesDelete(true), DataIterator(new StringClassPointerIterator<string>(text))
30 {}
31 
33 {
34  if(HandlesDelete) {
35 
36  SAFE_DELETE(DataIterator);
37  }
38 }
39 // ------------------------------------ //
40 DLLEXPORT void StringIterator::ReInit(std::unique_ptr<StringDataIterator>&& iterator)
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 }
61 
63 {
64  ReInit(std::make_unique<StringClassDataIterator<wstring>>(text));
65 }
66 
68 {
69  ReInit(std::make_unique<StringClassDataIterator<string>>(text));
70 }
71 
73 {
74  ReInit(std::make_unique<StringClassPointerIterator<wstring>>(text));
75 }
76 
78 {
79  ReInit(std::make_unique<StringClassPointerIterator<string>>(text));
80 }
81 // ------------------------------------ //
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 }
94 // ------------------------------------ //
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)
Iterator for string types.
uint32_t next(octet_iterator &it, octet_iterator end)
Definition: checked.h:137
virtual DLLEXPORT ~StringIterator()
DLLEXPORT void ReInit(std::unique_ptr< StringDataIterator > &&iterator)
Changes the current iterator to the new iterator and goes to the beginning.
DLLEXPORT int GetPreviousCharacter()
Gets the previous character.
#define ITR_COREDEBUG(x)
DLLEXPORT void SkipLineEnd()
Skips characters until the line number changes.
Iterator that doesn't hold own copy of a string.
static DLLEXPORT std::string CodePointToUtf8(int32_t codepoint)
Encodes a Unicode code point as an UTF8 string.
Definition: Convert.cpp:137
DLLEXPORT StringIterator()
Creates an empty iterator.
#define DLLEXPORT
Definition: Include.h:84
The access mask controls which registered functions and classes a script sees.
Definition: GameModule.h:12
#define SAFE_DELETE(x)
Definition: Define.h:151