aboutsummaryrefslogtreecommitdiffstats
path: root/fsa/src/alltest/lookup_test.cpp
blob: 19880d7a0a340dc5ee4cd32fa178b341d8acf121 (plain) (blame)
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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <string>

#include <vespa/fsa/fsa.h>

using namespace fsa;

int main(int argc, char** argv)
{

  if(argc!=2){
    std::cerr << "usage: lookup_test fsafile <input >output" << std::endl;
    return 1;
  }

  FSA f(argv[1]);
  FSA::HashedState fs(f);
  std::string input;

  while(!std::cin.eof()){
    getline(std::cin,input);

    if(input.size()>0){
      fs.start(input);
      if(fs.isFinal()){
        std::cout << "'" << input << "'" << " is accepted, hash value: " << fs.hash()
                  << ", data size: " << fs.dataSize()
                  << ", data string: \""
                  << std::setw(fs.dataSize()) << std::left << fs.data()
                  << "\"" << std::endl;
      }
      else{
        std::cout << "'" << input << "'" << " is not accepted." << std::endl;
      }
    }
  }

  return 0;
}