#include "support/lassert.h"
#include "support/lstrings.h"
-#include <cstring>
-#include <string>
-
using namespace std;
using namespace lyx::support;
// forward approach leads to very long, tedious code that would be
// much harder to understand and maintain. (AS)
- if (data.empty())
+ if (data.empty()) {
+ if (result)
+ *result = GlueLength();
return true;
+ }
string buffer = ltrim(data);
// To make isValidGlueLength recognize negative values as
// The parser may seem overkill for lengths without
// glue, but since we already have it, using it is
// easier than writing something from scratch.
- if (data.empty())
+ if (data.empty()) {
+ if (result)
+ *result = Length();
return true;
+ }
- string buffer = data;
- int pattern_index = 0;
- char pattern[3];
+ string buffer = data;
// To make isValidLength recognize negative values
// this little hack is needed:
int unit_index = 1; // entries at index 0 are sentinels
// construct "pattern" from "data"
+ string pattern;
while (!isEndOfData(buffer)) {
- if (pattern_index > 2)
+ if (pattern.size() > 2)
return false;
- pattern[pattern_index] = nextToken(buffer, number,
+ char const token = nextToken(buffer, number,
number_index, unit, unit_index);
- if (pattern[pattern_index] == 'E')
+ if (token == 'E')
return false;
- ++pattern_index;
+ pattern += token;
}
- pattern[pattern_index] = '\0';
// only the most basic pattern is accepted here
- if (strcmp(pattern, "nu") != 0)
+ if (pattern != "nu")
return false;
// It _was_ a correct length string.