N_("Column Width %"), N_("Page Width %"), N_("Line Width %"),
N_("Text Height %"), N_("Page Height %"), "" };
+
Length::UNIT unitFromString(string const & data)
{
int i = 0;
namespace {
-/// used to return numeric values in parsing vspace
-double number[4] = { 0, 0, 0, 0 };
-
-/// used to return unit types in parsing vspace
-Length::UNIT unit[4] = {
- Length::UNIT_NONE,
- Length::UNIT_NONE,
- Length::UNIT_NONE,
- Length::UNIT_NONE
-};
-
-/// the current position in the number array
-int number_index;
-/// the current position in the unit array
-int unit_index;
-
/// skip n characters of input
inline void lyx_advance(string & data, size_t n)
{
/**
* nextToken - return the next token in the input
* @param data input string
+ * @param number_index the current position in the number array
+ * @param unit_index the current position in the unit array
* @return a char representing the type of token returned
*
* The possible return values are :
* u a unit type (stored in unit array)
* E parse error
*/
-char nextToken(string & data)
+char nextToken(string & data, double * number, int & number_index,
+ Length::UNIT * unit, int & unit_index)
{
data = ltrim(data);
} // namespace anon
+
const char * stringFromUnit(int unit)
{
if (unit < 0 || unit > num_units)
// 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
}
// end of hack
- number_index = unit_index = 1; // entries at index 0 are sentinels
+ // used to return numeric values in parsing vspace
+ double number[4] = { 0, 0, 0, 0 };
+ // used to return unit types in parsing vspace
+ Length::UNIT unit[4] = {Length::UNIT_NONE, Length::UNIT_NONE,
+ Length::UNIT_NONE, Length::UNIT_NONE};
+ int number_index = 1; // entries at index 0 are sentinels
+ int unit_index = 1; // entries at index 0 are sentinels
// construct "pattern" from "data"
size_t const pattern_max_size = 20;
while (!isEndOfData(buffer)) {
if (pattern.size() > pattern_max_size)
return false;
- char const c = nextToken(buffer);
+ char const c = nextToken(buffer, number, number_index, unit,
+ unit_index);
if (c == 'E')
return false;
pattern.push_back(c);
// 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;
}
// end of hack
- number_index = unit_index = 1; // entries at index 0 are sentinels
+ // used to return numeric values in parsing vspace
+ double number[4] = { 0, 0, 0, 0 };
+ // used to return unit types in parsing vspace
+ Length::UNIT unit[4] = {Length::UNIT_NONE, Length::UNIT_NONE,
+ Length::UNIT_NONE, Length::UNIT_NONE};
+ int number_index = 1; // entries at index 0 are sentinels
+ int unit_index = 1; // entries at index 0 are sentinels
// construct "pattern" from "data"
while (!isEndOfData(buffer)) {
if (pattern_index > 2)
return false;
- pattern[pattern_index] = nextToken(buffer);
+ pattern[pattern_index] = nextToken(buffer, number,
+ number_index, unit, unit_index);
if (pattern[pattern_index] == 'E')
return false;
++pattern_index;