1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
// fgicomp.cc
#include "fgicomp.h"
#ifndef _FGSTRING_H
#include "fgstring.h"
#endif
#include <ctype.h>
FGIntegerComponent::FGIntegerComponent()
{
}
FGIntegerComponent::~FGIntegerComponent()
{
}
bool
FGIntegerComponent::MatchAndRankComponent(FGString& fnameRemainder,
int* pMatchVal) const
{
// Initialize to be safe
*pMatchVal = -1;
// Sanity checks
if (fnameRemainder.GetLength() < 1 || !isdigit(fnameRemainder[0])) {
return false;
}
unsigned int digits = 0;
// Build up the number here
FGString theInt;
do {
theInt += fnameRemainder[digits];
digits++;
} while (digits < fnameRemainder.GetLength() &&
isdigit(fnameRemainder[digits]));
// Set the match value
*pMatchVal = theInt.AToI();
// Chop off the digits we consumed
int charsLeft = fnameRemainder.GetLength() - digits;
FGString bitLeft = fnameRemainder.Right(charsLeft);
fnameRemainder = bitLeft;
return true;
}
|