File: fgscomp.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 (42 lines) | stat: -rw-r--r-- 878 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
// fgscomp.cc

#include "fgscomp.h"

FGStringComponent::FGStringComponent(const FGString& str)
: mStringBit(str)
{
}

FGStringComponent::~FGStringComponent()
{
}

bool
FGStringComponent::MatchAndRankComponent(FGString& fnameRemainder,
                                         int* pMatchVal) const
{
  // Match of a string fragment will always be valueless
  *pMatchVal = -1;

  // No match if our fragment is bigger than what's left
  int fragLen = mStringBit.GetLength();
  int compLen = fnameRemainder.GetLength();

  if (fragLen > compLen) {
    return false;
  }

  // Do comparison
  FGString leftBit = fnameRemainder.Left(fragLen);

  if (mStringBit != leftBit) {
    return false;
  }

  // OK so its a match
  // Truncate the filename remainder accordingly
  FGString fnameLeft = fnameRemainder.Right(compLen - fragLen);
  fnameRemainder = fnameLeft;

  return true;
}