File: fgicomp.cc

package info (click to toggle)
ftpgrab 0.1.2r-8
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, sarge
  • size: 376 kB
  • ctags: 335
  • sloc: cpp: 2,790; makefile: 26
file content (51 lines) | stat: -rw-r--r-- 980 bytes parent folder | download | duplicates (8)
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;
}