1 /** Helper functions for the SU(M)O-KIF file format.
2  *
3  * SUO-KIF is used the default encoding of the SUMO ontology.
4  */
5 module nxt.sumo_kif;
6 
7 @safe:
8 
9 bool isFormat(scope const(char)[] chars) pure nothrow @nogc
10 {
11     import nxt.array_algorithm : findSkip;
12     while (chars.findSkip('%'))
13     {
14         import std.ascii : isDigit;
15         if (chars.length >= 1 &&
16             (isDigit(chars[0]) ||
17              chars[0] == '*'))
18         {
19             return true;
20         }
21     }
22     return false;
23 }
24 
25 @safe pure unittest
26 {
27     assert("%1".isFormat);
28     assert(" %1 ".isFormat);
29 
30     assert("%2".isFormat);
31     assert(" %2 ".isFormat);
32 
33     assert("%*".isFormat);
34     assert(" %* ".isFormat);
35 
36     assert(!"%".isFormat);
37     assert(!"% ".isFormat);
38     assert(!" % ".isFormat);
39 
40     assert("%n %1".isFormat);
41     assert("%n %1".isFormat);
42     assert("%n %*".isFormat);
43 }
44 
45 bool isTermFormat(scope const(char)[] chars) pure nothrow @nogc
46 {
47     return !isFormat(chars);
48 }