• R/O
  • SSH
  • HTTPS

gtaconfig: Commit


Commit MetaInfo

Revision11 (tree)
Time2018-02-07 19:50:10
Authorquiret

Log Message

- made CSyntax copy-able and move-able

Change Summary

Incremental Difference

--- src/syntax.cpp (revision 10)
+++ src/syntax.cpp (revision 11)
@@ -2,7 +2,7 @@
22
33 #include <sdk/UniChar.h>
44
5-CSyntax::CSyntax(const char *buffer, size_t size)
5+CSyntax::CSyntax(const char *buffer, size_t size, size_t offset)
66 {
77 m_buffer = buffer;
88
@@ -10,10 +10,34 @@
1010 m_size = size;
1111 }
1212
13+CSyntax::CSyntax(CSyntax&& right)
14+{
15+ this->m_buffer = right.m_buffer;
16+ this->m_offset = right.m_offset;
17+ this->m_size = right.m_size;
18+
19+ right.m_buffer = NULL;
20+ right.m_offset = 0;
21+ right.m_size = 0;
22+}
23+
1324 CSyntax::~CSyntax()
1425 {
1526 }
1627
28+CSyntax& CSyntax::operator = (CSyntax&& right)
29+{
30+ this->m_buffer = right.m_buffer;
31+ this->m_offset = right.m_offset;
32+ this->m_size = right.m_size;
33+
34+ right.m_buffer = NULL;
35+ right.m_offset = 0;
36+ right.m_size = 0;
37+
38+ return *this;
39+}
40+
1741 inline bool IsName(char c)
1842 {
1943 switch (c)
@@ -61,7 +85,7 @@
6185 return false;
6286 }
6387
64-bool CSyntax::Finished()
88+bool CSyntax::Finished() const
6589 {
6690 return m_offset == m_size;
6791 }
@@ -291,30 +315,41 @@
291315
292316 bool CSyntax::GetToken(char *buffer, size_t len)
293317 {
294- size_t size;
295- const char *token = ParseToken( &size );
318+ if ( len == 0 )
319+ return false;
296320
321+ size_t tokSize;
322+ const char *token = ParseToken( &tokSize );
323+
297324 if ( !token )
298325 return false;
299326
300- size = std::min(len, size);
327+ size_t allow_size = std::min(len - 1, tokSize);
301328
302- memcpy( buffer, token, size );
329+ memcpy( buffer, token, allow_size );
303330
304- buffer[size] = 0;
331+ buffer[allow_size] = 0;
305332 return true;
306333 }
307334
308-bool CSyntax::HasToken(const char *tokenStr, bool direct, bool caseSensitive)
335+bool CSyntax::HasToken(const char *tokenStr, bool direct, bool caseSensitive, bool advanceAnyway)
309336 {
310- size_t begOff = this->GetOffset();
337+ size_t begOff;
311338
339+ if ( !advanceAnyway )
340+ {
341+ begOff = this->GetOffset();
342+ }
343+
312344 size_t tokenLen;
313345 const char *token = this->ParseToken( &tokenLen, direct );
314346
315347 if ( !token || !BoundedStringEqual( token, tokenLen, tokenStr, caseSensitive ) )
316348 {
317- this->SetOffset( begOff );
349+ if ( !advanceAnyway )
350+ {
351+ this->SetOffset( begOff );
352+ }
318353
319354 return false;
320355 }
@@ -483,9 +518,9 @@
483518 {
484519 bool skipped = SkipWhitespace();
485520
486- if ( !skipped )
521+ if ( !skipped )
487522 {
488- return false;
523+ return false;
489524 }
490525
491526 char read = this->ReadNext();
--- src/syntax.h (revision 10)
+++ src/syntax.h (revision 11)
@@ -16,10 +16,15 @@
1616 SINGLE
1717 };
1818
19- CSyntax(const char *buffer, size_t size);
19+ CSyntax(const char *buffer, size_t size, size_t offset = 0);
20+ CSyntax(const CSyntax& right) = default;
21+ CSyntax(CSyntax&& right);
2022 ~CSyntax();
2123
22- bool Finished();
24+ CSyntax& operator = (const CSyntax& right) = default;
25+ CSyntax& operator = (CSyntax&& right);
26+
27+ bool Finished() const;
2328 char ReadNext();
2429
2530 const char* ParseTokenEx(size_t *len, eTokenType& tokenType, bool parseDirect = false);
@@ -35,7 +40,7 @@
3540 static double TokenToDouble(const char *tok, size_t tokLen);
3641
3742 bool GetToken(char *buffer, size_t len);
38- bool HasToken(const char *tokenStr, bool direct = false, bool caseSensitive = false);
43+ bool HasToken(const char *tokenStr, bool direct = false, bool caseSensitive = false, bool advanceAnyway = false);
3944 bool HasTokenOfType(eTokenType tokType, bool direct = false);
4045 bool HasTokenSequence(const char *tokens, bool isDirect = false, bool caseSensitive = true, bool concat = false);
4146 bool HasAnyToken(bool direct = false);
Show on old repository browser