File: fgcharcomp.cc

package info (click to toggle)
ftpgrab 0.1.5-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 444 kB
  • sloc: cpp: 2,906; makefile: 103
file content (55 lines) | stat: -rw-r--r-- 1,176 bytes parent folder | download | duplicates (9)
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
52
53
54
55
// fgcharcomp.cc

#include "fgcharcomp.h"

#ifndef _FGSTRING_H
#include "fgstring.h"
#endif

#include <ctype.h>

FGCharacterComponent::FGCharacterComponent(bool isOptional)
{
  mIsOptional = isOptional;
}

FGCharacterComponent::~FGCharacterComponent()
{
}

bool
FGCharacterComponent::MatchAndRankComponent(FGString& fnameRemainder,
                                            int* pMatchVal) const
{
  // Initialize to be safe
  *pMatchVal = -1;

  // Sanity checks
  if (fnameRemainder.GetLength() < 1 || !isalpha(fnameRemainder[0])) {
    // May or may not be a "match" or such. If the character component
    // is NOT optional, it's not match. Otherwise it IS a match, with
    // minimal value
    if (!mIsOptional)
    {
      return false;
    }
    else
    {
      *pMatchVal = 0;
      return true;
    }
  }

  // The value returned will actually not be zero based, it will
  // be ASCII "A" based (65??)
  // It is of no conseqence
  *pMatchVal = toupper(fnameRemainder[0]);

  // Chop off the digits we consumed
  int charsLeft = fnameRemainder.GetLength() - 1;
  FGString bitLeft = fnameRemainder.Right(charsLeft);

  fnameRemainder = bitLeft;

  return true;
}