using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace UPImage.Common
{
public static class UpCommonLib
{
public const bool cTrue = true;
public const bool cFalse = false;
/* match */
/* environment variable to search for unipen.def and include files */
public const String cUnipenDefinition = "UNIPEN_DEFINITION_FILE";
public const String cUnipenIncludePath = "UNIPEN_INCLUDE_PATH";
public const String cIncludeInheritanceKey = ".INHERIT";
/*************************************************************************/
/* */
/* error */
/* */
/*************************************************************************/
public const String errOutOfMemory = "Out of memory";
public const String errInvalidKeyword = "in [{1}]: request for keyword \"{2}\" unsucessful (not found)\n";
public const String errMultipleCoords = "in [{1}]: Multiple coordinates ({2})\n";
public const String errMultipleHierarchies = "in [{1}]: Multiple hierarchies ({2})\n";
public const String errMultipleSets = "in [{1}]: Multiple sets ({2})\n";
public const String errNoCoord = "in [{1}]: No coordinates ({2})\n";
public const String errNoHierarchy = "in [{1}]: No hierarchy ({2})\n";
/* .SEGMENT quality NOTE NOTE NOTE: some extra quality indications are
added for the NICI .SEGMENT CHAR entries */
public const String qUnknown = "?";
public const String qBad = "BAD";
public const String qOk = "OK";
public const String qGood = "GOOD";
public const int Q_UNKNOWN = 0;
public const int Q_BAD = 1;
public const int Q_OK = 2;
public const int Q_GOOD = 3;
/* the NICI qualifications */
public const String qLbl = "LBL";
public const String qLbr = "LBR";
public const String qLbg = "LBG";
public const String qLbs = "LBS";
public const int Q_LBL = Q_OK;
public const int Q_LBR = Q_BAD;
public const int Q_LBS = 4;
/* sub string */
public const String cScheiders = "\t\n\r ";
/* unipen */
public const String cDefFile = "unipen.def";
public const String keyComment = ".COMMENT";
public const String keyCoord = ".COORD";
public const String keyHierarchy = ".HIERARCHY";
public const String keyInclude = ".INCLUDE";
public const String keyKeyword = ".KEYWORD";
public const String keyPenDown = ".PEN_DOWN";
public const String keyPenLapse = ".DT";
public const String keyPenUp = ".PEN_UP";
public const String keyReserve = ".RESERVE";
public const String keySegment = ".SEGMENT";
public const String keySampleRate = ".POINTS_PER_SECOND";
public const String keySet = ".START_SET";
public const String keyX_Dim = ".X_DIM";
public const String keyY_Dim = ".Y_DIM";
public const int cPenAdded = -1;
/// <summary>
/// //
/// </summary>
public static List <String> keyworkNames = new List<String>(61) { { ".COMMENT" }, { ".KEYWORD" },
{ ".INCLUDE" }, { ".VERSION" }, { ".DATA_SOURCE" }, { ".DATA_ID" }, { ".COORD" }, { ".HIERARCHY" },
{ ".DATA_CONTACT" }, { ".DATA_INFO" }, { ".SETUP" }, { ".PAD" }, { ".ALPHABET" }, { ".ALPHABET_FREQ" },
{ ".LEXICON_SOURCE" }, { ".LEXICON_ID" }, { ".LEXICON_CONTACT" }, { ".LEXICON_INFO" }, { ".LEXICON" },
{ ".LEXICON_FREQ" }, { ".X_DIM" }, { ".Y_DIM" }, { ".H_LINE" }, { ".V_LINE" }, { ".X_POINTS_PER_INCH" },
{ ".Y_POINTS_PER_INCH" }, { ".Z_POINTS_PER_INCH" }, { ".X_POINTS_PER_MM" }, { ".Y_POINTS_PER_MM" }, { ".Z_POINTS_PER_MM" },
{ ".POINTS_PER_GRAM" }, { ".POINTS_PER_SECOND" }, { ".PEN_DOWN" }, { ".PEN_UP" }, { ".DT" }, { ".DATE" }, { ".STYLE" },
{ ".WRITER" }, { ".COUNTRY" }, { ".HAND" }, { ".AGE" }, { ".SEX" }, { ".SKILL" }, { ".WRITER_INFO" }, { ".WRITER_ID" },{ ".RESERVE" },
{ ".SEGMENT" }, { ".START_SET" }, { ".START_BOX" }, { ".REC_SOURCE" }, { ".REC_ID" }, { ".REC_CONTACT" }, { ".REC_INFO" },
{ ".IMPLEMENT" }, { ".TRAINING_SET" }, { ".TEST_SET" }, { ".ADAPT_SET" }, { ".LEXICON_SET" }, { ".REC_TIME" }, { ".REC_LABELS" }, { ".REC_SCORES" } };
//Add all of the characters you wish to ignore in the method you choose
//Use a function here to get a return
public static bool SubStringSearch(List<string> ignoredStrings, string orginalString, string toMatch)
{
//Copy Your string to a temp
string tempString = orginalString;
bool match = false;
//Replace Everything that you don't want
if (ignoredStrings != null)
{
foreach (string item in ignoredStrings)
{
tempString = tempString.Replace(item, "");
}
}
//Check if your substring exist
if (tempString.Contains(toMatch))
{
match = true;
}
return match;
}
public static bool SubStringSearch(List<string> ignoredStrings, string replacedString, string orginalString, string toMatch)
{
//Copy Your string to a temp
string tempString = orginalString;
bool match = false;
//Replace Everything that you don't want
if (ignoredStrings != null)
{
foreach (string item in ignoredStrings)
{
tempString = tempString.Replace(item, replacedString);
}
}
//Check if your substring exist
if (tempString.Contains(toMatch))
{
match = true;
}
return match;
}
public static bool SubStringSearch(List<string> ignoredStrings, List<string> replacedStrings, string orginalString, string toMatch)
{
if (ignoredStrings.Count != replacedStrings.Count)
{
return false;
}
//Copy Your string to a temp
string tempString = orginalString;
bool match = false;
//Replace Everything that you don't want
if (ignoredStrings != null)
{
foreach (string item in ignoredStrings)
{
tempString = tempString.Replace(item, replacedStrings[ignoredStrings.IndexOf(item)]);
}
}
//Check if your substring exist
if (tempString.Contains(toMatch))
{
match = true;
}
return match;
}
public static bool SubStringSearch(this string s, string value, char[] ignoreChars, out string result)
{
if (String.IsNullOrEmpty(value))
throw new ArgumentException("Search value cannot be null or empty.", "value");
bool found = false;
int matches = 0;
int startIndex = -1;
int length = 0;
for (int i = 0; i < s.Length && !found; i++)
{
if (startIndex == -1)
{
if (s[i] == value[0])
{
startIndex = i;
++matches;
++length;
}
}
else
{
if (s[i] == value[matches])
{
++matches;
++length;
}
else
if (ignoreChars != null && ignoreChars.Contains(s[i]))
{
++length;
}
else
{
startIndex = -1;
matches = 0;
length = 0;
}
}
found = (matches == value.Length);
}
if (found)
{
result = s.Substring(startIndex, length);
}
else
{
result = null;
}
return found;
}
public static bool GetWordsFromString(List<string> ignoredStrings, string orginalString, out List<String> sList)
{
bool result = false;
if (String.IsNullOrEmpty(orginalString))
throw new ArgumentException("Original string cannot be null or empty.", "myString");
string tempString = orginalString;
try
{
//Replace Everything that you don't want
if (ignoredStrings != null)
{
foreach (string item in ignoredStrings)
{
tempString = tempString.Replace(item, "");
}
}
// if string have Tab character , replace it by " "
tempString = ReplaceSubString(tempString, "\t", " ");
String subString = tempString.Trim();
int index = subString.IndexOf(" ");
sList = new List<string>();
while (true)
{
if (index > 0)
{
String sWord = subString.Substring(0, index);
subString = subString.Substring(index + 1).Trim();
sList.Add(sWord);
index = subString.IndexOf(" ");
}
else
{
sList.Add(subString);
break;
}
}
result = true;
}
catch (Exception ex)
{
result = false;
throw new ArgumentException( ex.ToString());
}
return result;
}
public static bool GetWordsFromString(List<string> ignoredStrings, string replacedString, string orginalString, out List<String> sList)
{
bool result = false;
if (String.IsNullOrEmpty(orginalString))
throw new ArgumentException("Original string cannot be null or empty.", "myString");
string tempString = orginalString;
try
{
//Replace Everything that you don't want
if (ignoredStrings != null)
{
foreach (string item in ignoredStrings)
{
tempString = tempString.Replace(item, replacedString);
}
}
// if string have Tab character , replace it by " "
tempString = ReplaceSubString(tempString, "\t", " ");
String subString = tempString.Trim();
int index = subString.IndexOf(" ");
sList = new List<string>();
while (true)
{
if (index > 0)
{
String sWord = subString.Substring(0, index);
subString = subString.Substring(index + 1).Trim();
sList.Add(sWord);
index = subString.IndexOf(" ");
}
else
{
sList.Add(subString);
break;
}
}
result = true;
}
catch (Exception ex)
{
result = false;
throw new ArgumentException(ex.ToString());
}
return result;
}
public static String ReplaceSubString(String original, String oldString, String newString)
{
String tempString = original;
tempString = tempString.Replace(oldString, newString);
return tempString;
}
}
}