org.mitre.cpe.common
Class Utilities

java.lang.Object
  extended by org.mitre.cpe.common.Utilities

public class Utilities
extends java.lang.Object

A collection of utility functions for use with the org.mitre.cpe.matching and org.mitre.cpe.naming packages.

See Also:
cpe.mitre.org for more information.

Constructor Summary
Utilities()
           
 
Method Summary
static boolean containsWildcards(java.lang.String string)
          Searches string for special characters * and ?
static int countEscapeCharacters(java.lang.String str, int start, int end)
          Counts the number of escape characters in the string beginning and ending at the given indices
static int getUnescapedColonIndex(java.lang.String str)
          Searches a string for the first unescaped colon and returns the index of that colon
static int indexOf(java.lang.String str1, java.lang.String str2, int off)
          Searches a string for the first occurrence of another string, starting at a given offset.
static boolean isAlphanum(java.lang.String c)
          Returns true if the string contains only alphanumeric characters or the underscore character, false otherwise.
static boolean isEvenNumber(int num)
          Checks if given number is even or not
static java.lang.String reverse(java.lang.String s)
          Returns a copy of the given string in reverse order
static java.lang.String strcat(java.lang.String... strings)
          Concatenates an arbitrary number of strings, in the given order.
static int strchr(java.lang.String s, java.lang.String chr, int off)
          Searches a string for a character starting at a given offset.
static int strlen(java.lang.String s)
          Returns the number of characters in the given string.
static java.lang.String substr(java.lang.String s, int b, int e)
          Extracts the characters between b and e, from the string s.
static java.lang.String toLowercase(java.lang.String s)
          Converts all alphabetic characters in a String to lowercase.
static void validateFS(java.lang.String in)
          This function is not part of the reference implementation pseudo code found in the CPE 2.3 specification.
static void validateURI(java.lang.String in)
          This function is not part of the reference implementation pseudo code found in the CPE 2.3 specification.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Utilities

public Utilities()
Method Detail

strcat

public static java.lang.String strcat(java.lang.String... strings)
Concatenates an arbitrary number of strings, in the given order.

Parameters:
strings - strings to be concatenated
Returns:
a single string representing all the arguments, concatenated

substr

public static java.lang.String substr(java.lang.String s,
                                      int b,
                                      int e)
Extracts the characters between b and e, from the string s.

Parameters:
s - the string which the substring should be extracted from
b - beginning index
e - ending index
Returns:
the characters between index b and index e

strlen

public static int strlen(java.lang.String s)
Returns the number of characters in the given string.

Parameters:
s - the string
Returns:
the number of characters in s

strchr

public static int strchr(java.lang.String s,
                         java.lang.String chr,
                         int off)
Searches a string for a character starting at a given offset. Returns the offset of the character if found, -1 if not found.

Parameters:
s - string to be searched
chr - character to search for
off - offset to start at
Returns:
the integer offset of the character, or -1

toLowercase

public static java.lang.String toLowercase(java.lang.String s)
Converts all alphabetic characters in a String to lowercase.

Parameters:
s - string to convert to lowercase
Returns:
lowercase version of s

indexOf

public static int indexOf(java.lang.String str1,
                          java.lang.String str2,
                          int off)
Searches a string for the first occurrence of another string, starting at a given offset.

Parameters:
str1 - String to search.
str2 - String to search for.
off - Integer offset or -1 if not found.

containsWildcards

public static boolean containsWildcards(java.lang.String string)
Searches string for special characters * and ?

Parameters:
string - String to be searched
Returns:
true if string contains wildcard, false otherwise

isEvenNumber

public static boolean isEvenNumber(int num)
Checks if given number is even or not

Parameters:
num - number to check
Returns:
true if number is even, false if not

countEscapeCharacters

public static int countEscapeCharacters(java.lang.String str,
                                        int start,
                                        int end)
Counts the number of escape characters in the string beginning and ending at the given indices

Parameters:
str - string to search
start - beginning index
end - ending index
Returns:
number of escape characters in string

getUnescapedColonIndex

public static int getUnescapedColonIndex(java.lang.String str)
Searches a string for the first unescaped colon and returns the index of that colon

Parameters:
str - string to search
Returns:
index of first unescaped colon, or 0 if not found

isAlphanum

public static boolean isAlphanum(java.lang.String c)
Returns true if the string contains only alphanumeric characters or the underscore character, false otherwise.

Parameters:
c - the string in question
Returns:
true if c is alphanumeric or underscore, false if not

reverse

public static java.lang.String reverse(java.lang.String s)
Returns a copy of the given string in reverse order

Parameters:
s - the string to be reversed
Returns:
a reversed copy of s

validateURI

public static void validateURI(java.lang.String in)
                        throws java.text.ParseException
This function is not part of the reference implementation pseudo code found in the CPE 2.3 specification. It enforces two rules in the specification: URI must start with the characters "cpe:/" A URI may not contain more than 7 components If either rule is violated, a ParseException is thrown.

Throws:
java.text.ParseException

validateFS

public static void validateFS(java.lang.String in)
                       throws java.text.ParseException
This function is not part of the reference implementation pseudo code found in the CPE 2.3 specification. It enforces three rules found in the specification: Formatted string must start with the characters "cpe:2.3:" A formatted string must contain 11 components A formatted string must not contain empty components If any rule is violated, a ParseException is thrown.

Throws:
java.text.ParseException