$PBExportHeader$eaf_n_cst_stringservice.sru forward global type eaf_n_cst_stringservice from n_cst_baseservice end type end forward global type eaf_n_cst_stringservice from n_cst_baseservice end type global eaf_n_cst_stringservice eaf_n_cst_stringservice type variables end variables forward prototypes public function string gettoken (ref string as_original, string as_separator) public function string globalreplace (string as_original, string as_lookingfor, string as_replacewith, boolean ab_ignorecase) public function long lastpos (string as_lookin, string as_lookfor) public function long lastpos (string as_lookin, string as_lookfor, long al_start) public function string padleft (string as_original, long al_length) public function string padright (string as_original, long al_length) public function long parsearraytostring (string as_original[], string as_delimiter, ref string as_return) public function long parsestringtoarray (string as_original, string as_delimiter, ref string as_result[]) public function string quote (string as_original) public function long replaceparameter (ref string as_text, string as_parameters[], string as_parameterindetifier) public function long setkeyvalue (ref string as_keysandvalues, string as_keyword, string as_keyvalue, string as_separator) public function long countoccurrences (string as_original, string as_lookfor, boolean ab_ignorecase) public function boolean toboolean (string as_value) public function string getkeyvalue (ref string as_keysandvalues, string as_keyword, string as_separator) public function string format (readonly string as_source, string as_params[]) end prototypes public function string gettoken (ref string as_original, string as_separator);//////////////////////////////////////////////////////////////// // Description: // Strips off the first token from the passed in string. // Tokens are delimited/separated by the passed in value. // The original string has the returned token removed. // Revisions // 1.0 - Initial version // Arguments: // as_original - The string containing all the tokens // as_separator - The token separator // Returns: // <>"" - Success - the token // "" - no more tokens // "!" - Failure //////////////////////////////////////////////////////////////// // Copyright © 2000 - 2007 Youngsoft, Inc. All rights reserved. // Any distribution of the Youngsoft, Inc. Enterprise Application Framework // source code in whole or part by other than Youngsoft, Inc. is prohibited. //////////////////////////////////////////////////////////////// constant string METHOD_NAME = "getToken " If ib_trace Then inv_log.traceLog (METHOD_NAME, "(as_original, as_separator)~r~n" + & " as_original="+as_original + "~r~n" + & " as_separator="+as_separator) End If // Declare local variables long ll_pos_separator string ls_method_rv // Validate arguments If isNull(as_original) Then addError(METHOD_NAME, "Invalid as_original argument") Return "!" End If If isNull(as_separator) Or len(as_separator) = 0 Then addError(METHOD_NAME, "Invalid as_separator argument") Return "!" End If // Determine the position of the separator ll_pos_separator = pos(as_original, as_separator) // If no separtor is found, then the entire string is the token If ll_pos_separator <= 0 Then // Get the token ls_method_rv = as_original // Take out the token from the Original string as_original = "" Return ls_method_rv End If // Get the token ls_method_rv = mid (as_original, 1 , ll_pos_separator - 1) // Take out the token from the Original string as_original = right(as_original, & len(as_original) - (ll_pos_separator +len(as_separator) -1) ) Return ls_method_rv end function public function string globalreplace (string as_original, string as_lookingfor, string as_replacewith, boolean ab_ignorecase);//////////////////////////////////////////////////////////////// // Description: // Replaces all occurrences of "as_lookingfor" with "as_replaceWith" // found in the source string // // Similar function found in helperservice // Revisions // 1.0 - Initial version // Arguments: // as_original - The original string // as_lookingfor - The string to search for replacement // as_replacewith - The string to replace // ab_ignorecase - Should Case be ignored? // Returns: // The replaced string // If as_original is Null, then NULL is returned //////////////////////////////////////////////////////////////// // Copyright © 2000 - 2007 Youngsoft, Inc. All rights reserved. // Any distribution of the Youngsoft, Inc. Enterprise Application Framework // source code in whole or part by other than Youngsoft, Inc. is prohibited. //////////////////////////////////////////////////////////////// constant string METHOD_NAME = "globalReplace " If ib_trace Then inv_log.traceLog (METHOD_NAME, "(as_original, as_lookingfor, as_replacewith, ab_ignorecase)~r~n" + & " as_original="+as_original + "~r~n" + & " as_lookingfor="+as_lookingfor + "~r~n" + & " as_replacewith="+as_replacewith + "~r~n" + & " ab_ignorecase="+string(ab_ignorecase)) End If // Declare local variables long ll_pos_found long ll_len_tobereplaced long ll_len_replacewith string ls_case_source string ls_ignorecase_source // Validate arguments If isNull(as_original) Or len(trim(as_original)) = 0 Then // addError(METHOD_NAME, "Invalid as_original argument") Return as_original End If If isNull(as_lookingfor) Then addError(METHOD_NAME, "Invalid as_lookingfor argument") Return as_original End If If isNull(as_replacewith) Then addError(METHOD_NAME, "Invalid as_replacewith argument") Return as_original End If If isNull(ab_ignorecase) Then addError(METHOD_NAME, "Invalid ab_ignorecase argument") Return as_original End If // The working source strings ls_case_source = as_original ls_ignorecase_source = lower(as_original) // Determine the length of the "lookingFor" and "replaceWith" strings ll_len_tobereplaced = len(as_lookingfor) ll_len_replacewith = len(as_replacewith) // Is case being ignored If ab_ignorecase Then // Yes, case will be ignored as_lookingfor = lower(as_lookingfor) End If // Search for the first occurrence of "toBeReplaced" If ab_ignorecase Then ll_pos_found = pos(ls_ignorecase_source, as_lookingfor) Else ll_pos_found = pos(ls_case_source, as_lookingfor) End If Do While ll_pos_found > 0 // Replace "lookingFor" with "replaceWith" ls_case_source = replace(ls_case_source, ll_pos_found, ll_len_tobereplaced, as_replacewith) // Reset the string which ignores case ls_ignorecase_source = lower(ls_case_source) // Search for the next occurrence of "lookingFor" If ab_ignorecase Then ll_pos_found = pos(ls_ignorecase_source, as_lookingfor, & ll_pos_found + ll_len_replacewith) Else ll_pos_found = pos(ls_case_source, as_lookingfor, & ll_pos_found + ll_len_replacewith) End If Loop Return ls_case_source end function public function long lastpos (string as_lookin, string as_lookfor);//////////////////////////////////////////////////////////////// // Description: // Determines the Last Position of the passed in string within // another string // A backward search // Revisions // 1.0 - Initial version // Arguments: // as_lookin - The string to search in // as_lookfor - The string to search for // Returns: // >0 - Success - The location // 0 - means it was not located // -1 - Failure //////////////////////////////////////////////////////////////// // Copyright © 2000 - 2007 Youngsoft, Inc. All rights reserved. // Any distribution of the Youngsoft, Inc. Enterprise Application Framework // source code in whole or part by other than Youngsoft, Inc. is prohibited. //////////////////////////////////////////////////////////////// constant string METHOD_NAME = "lastPos " If ib_trace And ib_detailed Then inv_log.traceLog (METHOD_NAME, "(as_lookin, as_lookfor)~r~n" + & " as_lookin="+as_lookin + "~r~n" + & " as_lookfor="+as_lookfor) End If // Declare local variables long ll_pos // Function overload default is to search from end of string ll_pos = lastPos (as_lookin, as_lookfor, len(as_lookin)) Return ll_pos end function public function long lastpos (string as_lookin, string as_lookfor, long al_start);//////////////////////////////////////////////////////////////// // Description: // Determines the Last Position of the passed in string within // another string // A backward search // Revisions // 1.0 - Initial version // Arguments: // as_lookin - The string to search in // as_lookfor - The string to search for // al_start - The start position for the search // Returns: // >0 - Success - The location // 0 - means it was not located // -1 - Failure //////////////////////////////////////////////////////////////// // Copyright © 2000 - 2007 Youngsoft, Inc. All rights reserved. // Any distribution of the Youngsoft, Inc. Enterprise Application Framework // source code in whole or part by other than Youngsoft, Inc. is prohibited. //////////////////////////////////////////////////////////////// constant string METHOD_NAME = "lastPos " If ib_trace Then inv_log.traceLog (METHOD_NAME, "(as_lookin, as_lookfor, al_start)~r~n" + & " as_lookin="+as_lookin + "~r~n" + & " as_lookfor="+as_lookfor+"~r~n" + & " al_start="+string(al_start)) End If // Declare local variables long ll_pos long ll_idx // Validate arguments If isNull(as_lookin) Then addError(METHOD_NAME, "Invalid as_lookin argument") Return -1 End If If isNull(as_lookfor) Then addError(METHOD_NAME, "Invalid as_lookfor argument") Return -1 End If If isNull(al_start) Or al_start <= 0 Then addError(METHOD_NAME, "Invalid al_start argument") Return -1 End If // If appropriate, shorten the lookin string If len(as_lookin) > al_start Then as_lookin = left(as_lookin, al_start) End If // Confirm the value to LookFor is actually found in the string If pos(as_lookin, as_lookfor) = 0 Then // String being looked for is not found at all Return 0 End If // Search backward For ll_idx = al_start to 1 Step -1 ll_pos = pos(as_lookin, as_lookfor, ll_idx) If ll_pos = ll_idx Then // String being searched for been found. // This is the last position Return ll_idx End If Next // Not found Return 0 end function public function string padleft (string as_original, long al_length);//////////////////////////////////////////////////////////////// // Description: // Pads the original string with spaces on its left // Revisions // 1.0 - Initial version // Arguments: // as_original - The string to be padded // al_length - The desired length of the padded string // Returns: // The padded string // NULL if the original string was a NULL //////////////////////////////////////////////////////////////// // Copyright © 2000 - 2007 Youngsoft, Inc. All rights reserved. // Any distribution of the Youngsoft, Inc. Enterprise Application Framework // source code in whole or part by other than Youngsoft, Inc. is prohibited. //////////////////////////////////////////////////////////////// constant string METHOD_NAME = "padLeft " If ib_trace Then inv_log.traceLog (METHOD_NAME, "(as_original, al_length) " + & "as_original="+string(as_original)+" al_length="+string(al_length)) End If // Declare local variables long ll_len_original string ls_padding // Validate arguments If isNull(as_original) Then addError (METHOD_NAME, "Invalid as_original argument") Return as_original End If If isNull(al_length) Or al_length <= 0 Then addError (METHOD_NAME, "Invalid al_length argument") Return as_original End If // Determine the length of the original string ll_len_original = len(as_original) // Only perform action of the Original string is less than // the passed length If ll_len_original >= al_length Then Return as_original End If // Create the padding ls_padding = space(al_length - ll_len_original) // The padded string is the (Padding + Original) Return ls_padding + as_original end function public function string padright (string as_original, long al_length);//////////////////////////////////////////////////////////////// // Description: // Pads the original string with spaces to its Right // Revisions // 1.0 - Initial version // Arguments: // as_original - The string to be padded // al_length - The desired length of the padded string // Returns: // The padded string // NULL if the original string was a NULL //////////////////////////////////////////////////////////////// // Copyright © 2000 - 2007 Youngsoft, Inc. All rights reserved. // Any distribution of the Youngsoft, Inc. Enterprise Application Framework // source code in whole or part by other than Youngsoft, Inc. is prohibited. //////////////////////////////////////////////////////////////// constant string METHOD_NAME = "padRight " If ib_trace Then inv_log.traceLog (METHOD_NAME, "(as_original, al_length) " + & "as_original="+string(as_original)+" al_length="+string(al_length)) End If // Declare local variables long ll_len_original string ls_padding // Validate arguments If isNull(as_original) Then addError (METHOD_NAME, "Invalid as_original argument") Return as_original End If If isNull(al_length) Or al_length <= 0 Then addError (METHOD_NAME, "Invalid al_length argument") Return as_original End If // Determine the length of the original string ll_len_original = len(as_original) // Only perform action of the Original string is less than // the passed length If ll_len_original >= al_length Then Return as_original End If // Create the padding ls_padding = space(al_length - ll_len_original) // The padded string is the (Original + Padding) Return as_original + ls_padding end function public function long parsearraytostring (string as_original[], string as_delimiter, ref string as_return);//////////////////////////////////////////////////////////////// // Description: // Create a single string containing the contents of an array. // Each entry on the string is separated by the passed in delimeter. // Revisions // 1.0 - Initial version // Arguments: // as_original[] - The array containing all the tokens // as_delimiter - The delimeter to be placed between the tokens // as_return - Place holder for the resulting string // Returns: // 1 - Success // -1 - Failure //////////////////////////////////////////////////////////////// // Copyright © 2000 - 2007 Youngsoft, Inc. All rights reserved. // Any distribution of the Youngsoft, Inc. Enterprise Application Framework // source code in whole or part by other than Youngsoft, Inc. is prohibited. //////////////////////////////////////////////////////////////// constant string METHOD_NAME = "parseArrayToString " If ib_trace Then inv_log.traceLog (METHOD_NAME, "(as_original[], as_delimiter, ref as_return)" + & " as_delimiter="+as_delimiter) End If // Declare local variables long ll_idx long ll_upper // Perform cleanup as_return = "" If isNull(as_delimiter) Or len(as_delimiter) = 0 Then addError(METHOD_NAME, "Invalid as_delimiter argument") Return -1 End If // Get the number of entries on the array ll_upper = upperBound(as_original) // An empty Array returns an empty String If ll_upper = 0 Then Return 1 End If // Loop moving the array entries into the string For ll_idx = 1 to ll_upper // If appropriate, add the delimeter If ll_idx >= 2 Then as_return += as_delimiter End If // Add the entry as_return += as_original[ll_idx] Next Return 1 end function public function long parsestringtoarray (string as_original, string as_delimiter, ref string as_result[]);//////////////////////////////////////////////////////////////// // Description: // Parses the delimeted passed in string into an array // Create an array of strings containing the contents of the // passed in original string. Each entry on to be placed on the // array is denoted on the original string via the Delimeter // string. // // Similar function found in helperservice // Revisions // 1.0 - Initial version // Arguments: // as_original - The original string // as_delimiter - The delimiter separating the entries // as_result[] - Place holder for the parsed out entries // Returns: // 1 - Success // -1 - Failure //////////////////////////////////////////////////////////////// // Copyright © 2000 - 2007 Youngsoft, Inc. All rights reserved. // Any distribution of the Youngsoft, Inc. Enterprise Application Framework // source code in whole or part by other than Youngsoft, Inc. is prohibited. //////////////////////////////////////////////////////////////// constant string METHOD_NAME = "parseStringToArray " If ib_trace Then inv_log.traceLog (METHOD_NAME, "(as_original, as_delimiter, ref as_result[])~r~n" + & " as_original="+as_original + "~r~n" + & " as_delimiter="+as_delimiter) End If // Declare local variables long ll_len_delimeter long ll_pos_delimeter long ll_pos_start = 1 long ll_count = 0 string ls_possibleentry string ls_empty[] // Perform cleanup as_result = ls_empty // Validate arguments If isNull(as_original) Then addError(METHOD_NAME, "Invalid as_original argument") Return -1 End If If isNull(as_delimiter) Then addError(METHOD_NAME, "Invalid as_delimiter argument") Return -1 End If // Perform special checks If len(as_original) = 0 Then // Successfully found no entries Return 1 End If If as_original = as_delimiter Then // Successfully found no entries Return 1 End If If len(trim(as_original)) = 0 Then // Successfully found no entries Return 1 End If // Delimeter length ll_len_delimeter = Len(as_delimiter) // Find the first occurrence of the delimeter ll_pos_delimeter = pos(lower(as_original), lower(as_delimiter)) // Loop until no more entries are found Do While ll_pos_delimeter > 0 // An entry has been found ll_count ++ // Get the parsed entry as_result[ll_count] = & mid (as_original, ll_pos_start, (ll_pos_delimeter - ll_pos_start)) // Determine the new start position ll_pos_start = ll_pos_delimeter + ll_len_delimeter // Determine the position of the next delimeter ll_pos_delimeter = pos(lower(as_original), lower(as_delimiter), ll_pos_start) Loop // Check if the end of the source string is also an entry Or // Check to catch for the entire string being the one and only entry ls_possibleentry = mid (as_original, ll_pos_start, Len (as_original)) If len (ls_possibleentry) > 0 Then // An entry has been found ll_count++ as_result[ll_count] = ls_possibleentry End If Return 1 end function public function string quote (string as_original);//////////////////////////////////////////////////////////////// // Description: // Puts quotes are the Original string // Revisions // 1.0 - Initial version // Arguments: // as_original - The string to be quoted // Returns: // The quoted string // NULL if the original string was a NULL //////////////////////////////////////////////////////////////// // Copyright © 2000 - 2007 Youngsoft, Inc. All rights reserved. // Any distribution of the Youngsoft, Inc. Enterprise Application Framework // source code in whole or part by other than Youngsoft, Inc. is prohibited. //////////////////////////////////////////////////////////////// constant string METHOD_NAME = "quote " If ib_trace Then inv_log.traceLog (METHOD_NAME, "(as_original) " + & "as_original="+string(as_original)) End If // Validate arguments If isNull(as_original) Then addError (METHOD_NAME, "Invalid as_original argument") Return as_original End If // Return the quoted original Return '"' + as_original + '"' end function public function long replaceparameter (ref string as_text, string as_parameters[], string as_parameterindetifier);//////////////////////////////////////////////////////////////// // Description: // Replace the "Parameter place holders" inside the passed in // "text" with the information in the "parameters[]" // // Similar function found in helperservice // Revisions // 1.0 - Initial version // Arguments: // as_text - Place holder to receive and contain the replaced text // as_parameters[] - The parameters to be replaced into the text // as_parameterindetifier - The parameter indentifier to be located // and replaced with parameter values // Returns: // 1 - Success // -1 - Failure //////////////////////////////////////////////////////////////// // Copyright © 2000 - 2007 Youngsoft, Inc. All rights reserved. // Any distribution of the Youngsoft, Inc. Enterprise Application Framework // source code in whole or part by other than Youngsoft, Inc. is prohibited. //////////////////////////////////////////////////////////////// constant string METHOD_NAME = "replaceParameter " If ib_trace Then inv_log.traceLog (METHOD_NAME, "(ref as_text, as_parameters[], as_parameterindetifier)~r~n" + & " as_text="+as_text+"~r~n" + & " as_parameterindetifier="+as_parameterindetifier) End If // Declare local variables long ll_idx long ll_pos_start = 1 long ll_parameterupper long ll_parameterplaceholdercount long ll_pos_parameterindentifier // Validate arguments If isNull(as_text) Then addError (METHOD_NAME, "Invalid as_text argument") Return -1 End If If isNull(as_parameters) Then addError (METHOD_NAME, "Invalid as_parameters argument") Return -1 End If If isNull(as_parameterindetifier) Then addError (METHOD_NAME, "Invalid as_parameterindetifier argument") Return -1 End If // Get the number of parameter entries ll_parameterupper = upperBound(as_parameters) // Get number of parameter place holders in the passed in text If len(as_parameterindetifier) > 0 Then ll_parameterplaceholdercount = countOccurrences(as_text, as_parameterindetifier, true) End If // Quick check for no action needed If ll_parameterupper = 0 And ll_parameterplaceholdercount = 0 Then Return 1 End If // Make sure there are not any nulls in parameters For ll_idx = 1 to ll_parameterupper If isNull(as_parameters[ll_idx]) Then as_parameters[ll_idx] = "null" End If Next // Quick check for improper number of parameters If ll_parameterupper <> ll_parameterplaceholdercount Then // -- Problem encountered // Make the parameters passed in show up in the text If len(trim(as_text)) = 0 Then as_text = "'Blank Message' and " End If as_text += " Parameters(" For ll_idx = 1 to ll_parameterupper If ll_idx >= 2 Then as_text += ", " as_text += as_parameters[ll_idx] Next as_text += ")" addError (METHOD_NAME, & "Parameter count and parameters waiting to be replaced do not match:~r~n"+as_text) Return -1 End If // Replace the "Parameter Place Holders" with the "Parameter Values" For ll_idx = 1 to ll_parameterplaceholdercount ll_pos_parameterindentifier = pos(as_text, as_parameterindetifier, ll_pos_start) If ll_pos_parameterindentifier <=0 Then addError (METHOD_NAME, "Unexpected error (look into countOccurrences)") Return 1 End If as_text = replace (as_text, ll_pos_parameterindentifier, len(as_parameterindetifier), & as_parameters[ll_idx]) // Define the next start point ll_pos_start = ll_pos_parameterindentifier + len(as_parameters[ll_idx]) Next Return 1 end function public function long setkeyvalue (ref string as_keysandvalues, string as_keyword, string as_keyvalue, string as_separator);//////////////////////////////////////////////////////////////// // Description: // Receives a string with 0 to Many "Key=Value;" entries // where ";" is a common separator for the possible Many // "Key=Value" combinations. // Sets the KeyValue for the passed in Keyword using as_separator // as the separator. /// The method is Not case sensitive. // Revisions // 1.0 - Initial version // Arguments: // as_keysandvalues - The original and changed string containing // 0 to Many "Keys and Values" // as_keyword - The keyword being searched for in the Keys // as_keyvalue - The new Value to be assigned to the KeyWord // as_separator - The separator being used to separate multiple key/values // Returns: // 1 - Success // 0 - Value could not be assigned // -1 - Failure //////////////////////////////////////////////////////////////// // Copyright © 2000 - 2007 Youngsoft, Inc. All rights reserved. // Any distribution of the Youngsoft, Inc. Enterprise Application Framework // source code in whole or part by other than Youngsoft, Inc. is prohibited. //////////////////////////////////////////////////////////////// constant string METHOD_NAME = "setKeyValue " If ib_trace Then inv_log.traceLog (METHOD_NAME, "(as_keysandvalues, as_keyword, as_keyvalue, as_separator) ~r~n" + & " as_keysandvalues="+as_keysandvalues+ "~r~n" + & " as_keyword="+as_keyword+ "~r~n" + & " as_keyvalue="+as_keyvalue+ "~r~n" + & " as_separator="+as_separator) End If // Declare local variables long ll_len_keysandvalues long ll_len_keyword long ll_pos_start = 1 long ll_pos_keyword long ll_pos_separator long ll_pos_equal string ls_valueafterpossiblekey // Validate arguments If IsNull(as_keysandvalues) Then addError (METHOD_NAME, "Invalid as_keysandvalues argument") Return -1 End If If IsNull(as_keyword) Or len(trim(as_keyword))= 0 Then addError (METHOD_NAME, "Invalid as_keyword argument") Return -1 End If If IsNull(as_keyvalue) Then addError (METHOD_NAME, "Invalid as_keyvalue argument") Return -1 End If If IsNull(as_separator) Then addError (METHOD_NAME, "Invalid as_separator argument") Return -1 End If // Determine the lengths ll_len_keysandvalues = len(as_keysandvalues) ll_len_keyword = len(as_keyword) Do // Find an occurrence of the Keyword ll_pos_keyword = pos (lower(as_keysandvalues), lower(as_keyword), ll_pos_start) If ll_pos_keyword > 0 Then // Get the value after the key to see if it contains an "=" next ls_valueafterpossiblekey = leftTrim (right (as_keysandvalues, & ll_len_keysandvalues - (ll_pos_keyword + ll_len_keyword - 1))) If left (ls_valueafterpossiblekey, 1) = "=" Then // -- Yes, the Keyword has been found // Find the positions of the "=" and the separator ll_pos_equal = pos (as_keysandvalues, "=", ll_pos_keyword + 1) ll_pos_separator = pos (as_keysandvalues, as_separator, ll_pos_equal + 1) // Check if a position for the separator was found. If ll_pos_separator > 0 Then // Separator was found, replace the current string between // the "=" and the separator as_keysandvalues = left(as_keysandvalues, ll_pos_equal) + & as_keyvalue + as_separator + & right(as_keysandvalues, ll_len_keysandvalues - ll_pos_separator) Else // Separator not found, the separator is the end of the string // Replace the string from the "=" to the end of the string as_keysandvalues = left(as_keysandvalues, ll_pos_equal) + as_keyvalue End If Return 1 End If // Define the new Start point ll_pos_start = ll_pos_keyword + 1 End If Loop While ll_pos_keyword > 0 // The Keyword was Not found Return 0 end function public function long countoccurrences (string as_original, string as_lookfor, boolean ab_ignorecase);//////////////////////////////////////////////////////////////// // Description: // Counts the number of occurrences of the LookFor string // within the Original string // // Similar function found in helperservice // Revisions // 1.0 - Initial version // Arguments: // as_original - The string to be searched // as_lookfor - The string to be looked for // ab_ignorecase - Ignore case or not // Returns: // Number of occurrences found // -1 - Failure //////////////////////////////////////////////////////////////// // Copyright © 2000 - 2007 Youngsoft, Inc. All rights reserved. // Any distribution of the Youngsoft, Inc. Enterprise Application Framework // source code in whole or part by other than Youngsoft, Inc. is prohibited. //////////////////////////////////////////////////////////////// constant string METHOD_NAME = "countOccurrences " If ib_trace Then inv_log.traceLog (METHOD_NAME, "(as_original, as_lookfor, ab_ignorecase)~r~n" + & " as_original="+string(as_original)+"~r~n" + & " as_lookfor="+as_lookfor+ "~r~n" + & " ab_ignorecase="+string(ab_ignorecase)) End If // Declare local variables long ll_pos_found long ll_len_lookfor long ll_count // Validate arguments If isNull(as_original) Then addError (METHOD_NAME, "Invalid as_original argument") Return -1 End If If isNull(as_lookfor) Or len(as_lookfor) = 0 Then addError (METHOD_NAME, "Invalid as_lookfor argument") Return -1 End If If isNull(ab_ignorecase) Then addError (METHOD_NAME, "Invalid ab_ignorecase argument") Return -1 End If // Quick check If len(as_original) = 0 Then Return 0 End If // Determine the length of the string being searched for ll_len_lookfor = len(as_lookfor) // Should case be ignored If ab_ignorecase Then as_original = lower(as_original) as_lookfor = lower(as_lookfor) End If // Loop around the original string finding all the occurrences ll_pos_found = pos(as_original, as_lookfor, 1) Do While ll_pos_found > 0 // Found an occurrence ll_count ++ // Attempt to find another occurrence ll_pos_found = pos(as_original, as_lookfor, (ll_pos_found + ll_len_lookfor)) Loop // Return the number of occurrences found Return ll_count end function public function boolean toboolean (string as_value);//////////////////////////////////////////////////////////////// // Description: // Converts a text value to boolean // Revisions // 3.0 - Initial version // Arguments: // as_value - text value to be converted // Returns: // Boolean //////////////////////////////////////////////////////////////// // Copyright © 2000 - 2007 Youngsoft, Inc. All rights reserved. // Any distribution of the Youngsoft, Inc. Enterprise Application Framework // source code in whole or part by other than Youngsoft, Inc. is prohibited. //////////////////////////////////////////////////////////////// constant string METHOD_NAME = "toBoolean ( String ) " boolean lb_value if isNull( as_value ) then return false end if as_value = upper(trim(as_value)) lb_value = ( (as_value = "YES" or as_value = "TRUE") ) return lb_value end function public function string getkeyvalue (ref string as_keysandvalues, string as_keyword, string as_separator);//////////////////////////////////////////////////////////////// // Description: // Receives a string with 0 to Many "Key=Value;" entries // where ";" is a common separator for the possible Many // "Key=Value" combinations. // Returns the Value on the first matching Key encountered. // Returns the original passed in string minus the entry returned. /// The method is Not case sensitive. // // Similar function found in helperservice // Revisions // 1.0 - Initial version // Arguments: // as_keysandvalues - The original and changed string containing // 0 to Many "Keys and Values" // as_keyword - The keyword being searched for in the Keys // as_separator - The separator being used to separate multiple key/values // Returns: // Returns the Value on the first matching Key encountered // "!" - Failure //////////////////////////////////////////////////////////////// // Copyright © 2000 - 2007 Youngsoft, Inc. All rights reserved. // Any distribution of the Youngsoft, Inc. Enterprise Application Framework // source code in whole or part by other than Youngsoft, Inc. is prohibited. //////////////////////////////////////////////////////////////// constant string METHOD_NAME = "getKeyValue " If ib_trace Then inv_log.traceLog (METHOD_NAME, "(as_keysandvalues, as_keyword, as_separator) ~r~n" + & " as_keysandvalues="+as_keysandvalues+ "~r~n" + & " as_keyword="+as_keyword+ "~r~n" + & " as_separator="+as_separator) End If // Declare local variables long ll_pos_start =1 long ll_pos_keyword long ll_pos_separator long ll_pos_point long ll_len_keyword long ll_len_separator long ll_len_keysandvalues long ll_equalsigndistance long ll_equal string ls_value string ls_possibleequalsign string ls_source string ls_exact string ls_newkeysandvalues boolean lb_valuefound = false boolean lb_done = false // Validate arguments If isNull(as_keysandvalues) Then addError(METHOD_NAME, "Invalid as_keysandvalues argument") Return "!" End If If isNull(as_keyword) Then addError(METHOD_NAME, "Invalid as_keyword argument") Return "!" End If If isNull(as_separator) or len(trim(as_separator)) = 0 Then addError(METHOD_NAME, "Invalid as_separator argument") Return "!" End If // Determine the lengths ll_len_keyword = len(as_keyword) ll_len_separator = len(as_separator) ll_len_keysandvalues = len(as_keysandvalues) // Loop until the right Key/Value is encountered or // no matching Key is encountered Do While (Not lb_valuefound And Not lb_done) // Find a possible occurrence of the Key ll_pos_keyword = pos (lower(as_keysandvalues), lower(as_keyword), ll_pos_start) // If no possible key is found, then we are done lb_done = (ll_pos_keyword <= 0) If Not lb_done Then // A possible occurrence of the Key has been located // Check if the equal sign is next ls_possibleequalsign = mid(as_keysandvalues, ll_pos_keyword + ll_len_keyword) If left(trim(ls_possibleequalsign), 1) = "=" Then // Yes, the Key/Value wanted has been found lb_valuefound = true // Find the distance of the "=" sign ll_equalsigndistance = pos(ls_possibleequalsign, "=") - 1 // Define the position point ll_pos_point = ll_pos_keyword + ll_len_keyword + ll_equalsigndistance + 1 // Find the position of the separator ll_pos_separator = pos (as_keysandvalues, as_separator, ll_pos_point) If ll_pos_separator = 0 Then // There are no more separators (end of string) ll_pos_separator = ll_len_keysandvalues + 1 End If // Get the value ls_value = mid(as_keysandvalues, & ll_pos_point, ll_pos_separator - ll_pos_point) // Take out the Key/Value from the original string ls_newkeysandvalues = rightTrim(left(as_keysandvalues, ll_pos_keyword - 1)) ls_newkeysandvalues += leftTrim(right(as_keysandvalues, ll_len_keysandvalues - (ll_pos_point + len(ls_value)))) as_keysandvalues = ls_newkeysandvalues End If // Define the next starting position to base the next search on ll_pos_start = ll_pos_keyword + ll_len_keyword End If Loop Return ls_value end function public function string format (readonly string as_source, string as_params[]);long ll_count, n string ls_msg ll_count = UPPERBOUND(as_params) ls_msg = as_source FOR n = 1 to ll_count ls_msg = this.globalreplace(ls_msg, "{" + STRING(n) + "}", as_params[n], true) NEXT RETURN ls_msg end function on eaf_n_cst_stringservice.create call super::create end on on eaf_n_cst_stringservice.destroy call super::destroy end on
- Sources
- EAF.NET
- eaf_shared
- eaf_n_cst_stringservice.sru
File: eaf_n_cst_stringservice.sru
Size: 35795
Date: Tue, 22 Jan 2008 23:39:11 +0100
Size: 35795
Date: Tue, 22 Jan 2008 23:39:11 +0100
- n_cst_baseservice eaf_n_cst_stringservice(sru)
- countoccurrences (string as_original, string as_lookfor, boolean ab_ignorecase) returns long
- format (readonly string as_source, string as_params[]) returns string
- getkeyvalue (ref string as_keysandvalues, string as_keyword, string as_separator) returns string
- gettoken (ref string as_original, string as_separator) returns string
- globalreplace (string as_original, string as_lookingfor, string as_replacewith, boolean ab_ignorecase) returns string
- lastpos (string as_lookin, string as_lookfor) returns long
- lastpos (string as_lookin, string as_lookfor, long al_start) returns long
- padleft (string as_original, long al_length) returns string
- padright (string as_original, long al_length) returns string
- parsearraytostring (string as_original[], string as_delimiter, ref string as_return) returns long
- parsestringtoarray (string as_original, string as_delimiter, ref string as_result[]) returns long
- quote (string as_original) returns string
- replaceparameter (ref string as_text, string as_parameters[], string as_parameterindetifier) returns long
- setkeyvalue (ref string as_keysandvalues, string as_keyword, string as_keyvalue, string as_separator) returns long
- toboolean (string as_value) returns boolean