Add utility functions for parsing a range expression.
- Fills out the supplied RangeList with the set of ranges that the expression stipulates.
This commit is contained in:
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "FunctionInstance.h"
|
#include "FunctionInstance.h"
|
||||||
#include "Image.h"
|
#include "Image.h"
|
||||||
|
#include "RangeList.h"
|
||||||
#include "StackFrame.h"
|
#include "StackFrame.h"
|
||||||
#include "Team.h"
|
#include "Team.h"
|
||||||
#include "TeamMemoryBlock.h"
|
#include "TeamMemoryBlock.h"
|
||||||
@@ -388,3 +389,66 @@ UiUtils::DumpMemory(BString& _output, int32 indentLevel,
|
|||||||
|
|
||||||
_output.Append("\n");
|
_output.Append("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static status_t ParseRangeString(BString& rangeString, int32& lowerBound,
|
||||||
|
int32& upperBound)
|
||||||
|
{
|
||||||
|
lowerBound = atoi(rangeString.String());
|
||||||
|
int32 index = rangeString.FindFirst('-');
|
||||||
|
if (index >= 0) {
|
||||||
|
rangeString.Remove(0, index + 1);
|
||||||
|
upperBound = atoi(rangeString.String());
|
||||||
|
} else
|
||||||
|
upperBound = lowerBound;
|
||||||
|
|
||||||
|
if (lowerBound > upperBound)
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*static*/ status_t
|
||||||
|
UiUtils::ParseRangeExpression(const BString& rangeExpression, int32 lowerBound,
|
||||||
|
int32 upperBound, RangeList& _output)
|
||||||
|
{
|
||||||
|
if (rangeExpression.IsEmpty())
|
||||||
|
return B_BAD_DATA;
|
||||||
|
|
||||||
|
BString dataString = rangeExpression;
|
||||||
|
dataString.RemoveAll(" ");
|
||||||
|
|
||||||
|
// first, tokenize the range list to its constituent child ranges.
|
||||||
|
int32 index;
|
||||||
|
int32 lowValue;
|
||||||
|
int32 highValue;
|
||||||
|
BString tempRange;
|
||||||
|
while (!dataString.IsEmpty()) {
|
||||||
|
index = dataString.FindFirst(',');
|
||||||
|
if (index == 0)
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
else if (index > 0) {
|
||||||
|
dataString.MoveInto(tempRange, 0, index);
|
||||||
|
dataString.Remove(0, 1);
|
||||||
|
} else {
|
||||||
|
tempRange = dataString;
|
||||||
|
dataString.Truncate(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
status_t result = ParseRangeString(tempRange, lowValue, highValue);
|
||||||
|
if (result != B_OK)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
if (lowValue < lowerBound || highValue > upperBound)
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
|
result = _output.AddRange(lowValue, highValue);
|
||||||
|
if (result != B_OK)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
tempRange.Truncate(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
class BString;
|
class BString;
|
||||||
class BVariant;
|
class BVariant;
|
||||||
|
class RangeList;
|
||||||
class StackFrame;
|
class StackFrame;
|
||||||
class Team;
|
class Team;
|
||||||
class TeamMemoryBlock;
|
class TeamMemoryBlock;
|
||||||
@@ -50,6 +51,11 @@ public:
|
|||||||
TeamMemoryBlock* block,
|
TeamMemoryBlock* block,
|
||||||
target_addr_t address, int32 itemSize,
|
target_addr_t address, int32 itemSize,
|
||||||
int32 displayWidth, int32 count);
|
int32 displayWidth, int32 count);
|
||||||
|
|
||||||
|
static status_t ParseRangeExpression(
|
||||||
|
const BString& rangeString,
|
||||||
|
int32 lowerBound, int32 upperBound,
|
||||||
|
RangeList& _output);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user