File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -84,19 +84,48 @@ bool DbcIdentifierToken::acceptsChar(QChar ch)
8484
8585
8686DbcStringToken::DbcStringToken (int line, int column)
87- : DbcToken(line, column, dbc_tok_string)
87+ : DbcToken(line, column, dbc_tok_string),
88+ _done(false ),
89+ _escape(false )
8890{
8991}
9092
93+ // Store string including quotes, as:
94+ // "some string"
95+ // which may include '\'-escaped double quotes, leading to something like
96+ // "some string is \"this\""
97+ // and '\' can be escaped as well
98+ // "this is a valid \\ acceptable string"
9199bool DbcStringToken::acceptsChar (QChar ch)
92100{
93- if (_data.isEmpty ()) {
94- return (ch==' "' );
95- } else if (_data.length ()<2 ) {
96- return true ;
97- } else {
98- return !_data.endsWith (' "' );
99- }
101+ if (_done) {
102+ return false ;
103+ }
104+
105+ switch (_data.length ()) {
106+ // Start of string must be '"'
107+ case 0 :
108+ return (ch == ' "' );
109+ // Can't look to index -1, so accept anything
110+ case 1 :
111+ _escape = (ch == ' \\ ' );
112+ _done = (ch == ' "' );
113+ return true ;
114+ // Accept anything until an unescaped '"'
115+ default :
116+ if (_escape) {
117+ _escape = false ;
118+ } else {
119+ if (ch == ' \\ ' ) {
120+ _escape = true ;
121+ }
122+ if (ch == ' "' ) {
123+ _data.replace (QRegExp (" \\\\ (.)" ), " \\ 1" );
124+ _done = true ;
125+ }
126+ }
127+ return true ;
128+ }
100129}
101130
102131
Original file line number Diff line number Diff line change @@ -83,6 +83,9 @@ class DbcStringToken : public DbcToken {
8383public:
8484 DbcStringToken (int line, int column);
8585 virtual bool acceptsChar (QChar ch);
86+ private:
87+ bool _done;
88+ bool _escape;
8689};
8790
8891class DbcRegExpToken : public DbcToken {
You can’t perform that action at this time.
0 commit comments