'encoding UTF-8 Do not remove or change this line!
'**************************************************************
'
' Licensed to the Apache Software Foundation (ASF) under one
' or more contributor license agreements. See the NOTICE file
' distributed with this work for additional information
' regarding copyright ownership. The ASF licenses this file
' to you under the Apache License, Version 2.0 (the
' "License"); you may not use this file except in compliance
' with the License. You may obtain a copy of the License at
'
' http://www.apache.org/licenses/LICENSE-2.0
'
' Unless required by applicable law or agreed to in writing,
' software distributed under the License is distributed on an
' "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
' KIND, either express or implied. See the License for the
' specific language governing permissions and limitations
' under the License.
'
'**************************************************************
'*
'* short description : tools for evaluation of key=value datalists
'*
'*******************************************************************************
' **
' #1 hGetDataPairAsString ' retrieve key=value from a list
' #1 hGetValueForPairAsString ' retrieve value from a key=value as string
' #1 hGetValueForPairAsLong ' retrieve value from a key=value as long integer
' #1 hGetValueForKeyAsInt ' retrieve value for a specified key as integer
' #1 hGetValueForKeyAsLong ' retrieve value for a specified key as long integer
' #1 hGetKeyForPairAsString ' retrieve key from key=value as string
' #1 hGetKeyForValueAsString ' retrieve key for a specified value as string
' #1 hGetKeyForValueAsInt ' retrieve key for a specified value as int
' #1 hGetIndexForKeyAsInt ' retrieve the index for a key in a list
' #1 KeyCompare ' compare two keys
' **
'\******************************************************************************
' Some variables explained:
'
' cComp is the KEY belonging to the VALUE above for reverse test
'
' NOTE: Other related functions can be found in global/tools/inc/t_filters.inc
'*******************************************************************************
function hGetDataPairAsString( sKey as string, sVal as long ) as string
'///
Concatenate two strings and insert an = sign
'///About "KEY"-functions:
'///These functions are used whenever
'///+ data is to be processed that is stored in a key=value format.
'///+ They handle a single string or a list of strings
'///+ to e.g. isolate a key, a value or to just retrieve the pair.
'///Input:
'///
'///+- KEY (string)
'///
'///+- Anything but should not contain # or '
'///
'///+- VALUE (string)
'///
'///+- Anything but should not contain # or '
'///
'///
'///Returns:
'///
'///+- KEY=VALUE pair (string)
'///
'///Description:
'///
'///+- Returns string1=string2
hGetDataPairAsString() = sKey & "=" & sVal
'///
end function
'*******************************************************************************
function hGetValueForPairAsString( cLine as string ) as string
'///Retrieve value from a key=value string
'///About "KEY"-functions:
'///These functions are used whenever
'///+ data is to be processed that is stored in a key=value format.
'///+ They handle a single string or a list of strings
'///+ to e.g. isolate a key, a value or to just retrieve the pair.
'///Input:
'///
'///+- KEY=VALUE pair (string)
'///
'///Returns:
'///
'///+- VALUE (string)
'///
'///+- Anything after the = character
'///
'///
'///Description:
'///
dim iCharPos as integer
'///+- Locate the equal sign
iCharPos = instr( cLine , "=" )
iCharPos = len( cLine ) - iCharPos
'///+- Isolate everything to the right of the equal sign
'///+- Return the value as string
hGetValueForPairAsString() = right( cLine , iCharPos )
'///
end function
'*******************************************************************************
function hGetValueForPairAsLong( cLine as string ) as long
'///Retrieve the value from a key=value pair as long
'///About "KEY"-functions:
'///These functions are used whenever
'///+ data is to be processed that is stored in a key=value format.
'///+ They handle a single string or a list of strings
'///+ to e.g. isolate a key, a value or to just retrieve the pair.
'///Input:
'///
'///+- KEY=VALUE pair (string)
'///
'///Returns:
'///
'///+- VALUE (long)
'///
'///+- Anything after the = character as long integer value
'///
'///
'///Description:
'///
dim iCharPos as integer
'///+- Locate the equal sign
iCharPos = instr( cLine , "=" )
iCharPos = len( cLine ) - iCharPos
'///+- Isolate and return the Value as long datatype
hGetValueForPairAsLong = val( right( cLine , iCharPos ))
'///
end function
'*******************************************************************************
function hGetValueForKeyAsInt( lsList() as string, sKey as string ) as integer
'///Retrieve the value of a key=value pair as integer
'///About "KEY"-functions:
'///These functions are used whenever
'///+ data is to be processed that is stored in a key=value format.
'///+ They handle a single string or a list of strings
'///+ to e.g. isolate a key, a value or to just retrieve the pair.
'///Prerequisite: Array compatible to listfuncs, known, valid key
'///Input:
'///
'///+- List of KEY=VALUE pairs (string)
'///
'///+- List must be compatible to listfunctions (see t_listfuncs.inc)
'///
'///+- Key to be searched for within the list (string)
'///
'///+- Key must be valid
'///
'///
'///Returns:
'///
'///+- VALUE (integer)
'///
'///+- The value for a given key
'///
'///
'///Description:
'///
dim iItem as integer
dim cString as string
dim cComp as string
hGetValueForKeyAsInt() = 0
' Scan through the list and look for sKey. If found, return the Value
' (everything to the right of the '=')
'///+- Search the list for the key
for iItem = 1 to listcount( lsList() )
if( instr( lsList( iItem ) , sKey ) <> 0 ) then
'///+- Verify that this is really the correct key by reverse-checking
cComp = hGetKeyforPairAsString( lsList( iItem ) )
'///+- Retrieve the value for the key as string
if( sKey = cComp ) then
cString = hGetValueForPairAsString( lsList( iItem ) )
iItem = listcount( lsList() ) + 1
endif
endif
next iItem
'///+- Convert the stringvalue to integer and return it
hGetValueForKeyAsInt() = val( cString )
'///
end function
'*******************************************************************************
function hGetValueForKeyAsLong( lsList() as string, sKey as string ) as long
'///Retrieve the value of a key=value pair as integer
'///About "KEY"-functions:
'///These functions are used whenever
'///+ data is to be processed that is stored in a key=value format.
'///+ They handle a single string or a list of strings
'///+ to e.g. isolate a key, a value or to just retrieve the pair.
'///Prerequisite: Array compatible to listfuncs, known, valid key
'///Input:
'///
'///+- List of KEY=VALUE pairs (string)
'///
'///+- List must be compatible to listfunctions (see t_listfuncs.inc)
'///
'///+- Key to be searched for within the list (string)
'///
'///+- Key must be valid
'///
'///
'///Returns:
'///
'///+- VALUE (long integer)
'///
'///+- The value for a given key
'///
'///
'///Description:
'///
dim iItem as integer
dim cString as string
dim cComp as string
hGetValueForKeyAsInt() = 0
' Scan through the list and look for sKey. If found, return the Value
' (everything to the right of the '=')
'///+- Search the list for the key
for iItem = 1 to listcount( lsList() )
if( instr( lsList( iItem ) , sKey ) <> 0 ) then
'///+- Verify that this is really the correct key by reverse-checking
cComp = hGetKeyforPairAsString( lsList( iItem ) )
'///+- Retrieve the value for the key as string
if( sKey = cComp ) then
cString = hGetValueForPairAsString( lsList( iItem ) )
iItem = listcount( lsList() ) + 1
endif
endif
next iItem
'///+- Convert the stringvalue to long integer and return it
hGetValueForKeyAsInt() = val( cString )
'///
end function
'*******************************************************************************
function hGetKeyForPairAsString( cLine as string ) as string
'///Retrieve the KEY from a key=value pair
'///About "KEY"-functions:
'///These functions are used whenever
'///+ data is to be processed that is stored in a key=value format.
'///+ They handle a single string or a list of strings
'///+ to e.g. isolate a key, a value or to just retrieve the pair.
'///Input:
'///
'///+- KEY=VALUE pair (string)
'///
'///Returns:
'///
'///+- KEY (string)
'///
'///+- Anything before the = character
'///
'///
'///Description:
'///
dim iCharPos as integer
iCharPos = instr( cLine , "=" )
'///+- get the string to the left of the = char
if ( iCharPos > 0 ) then
hGetKeyForPairAsString() = left( cLine , iCharPos -1 )
else
warnlog( "Invalid string passed to hGetKeyForPairAsString" )
printlog( "It was: " & cLine )
endif
'///+- Return the key
'///
end function
'*******************************************************************************
function hGetKeyForValueAsString( lsList() as string, sVal as string ) as string
'///Retrieve the KEY for a known VALUE from a key=value pair
'///About "KEY"-functions:
'///These functions are used whenever
'///+ data is to be processed that is stored in a key=value format.
'///+ They handle a single string or a list of strings
'///+ to e.g. isolate a key, a value or to just retrieve the pair.
'///Prerequisite: List compatible to listfuncs, known VALUE for pair
'///Input:
'///
'///+- List of KEY=VALUE pairs (string)
'///
'///+- VALUE (string)
'///
'///+- Absolute match required.
'///
'///
'///Returns:
'///
'///+- KEY (string)
'///
'///Description:
'///
' This function returns the value of a key as string.
' The form of the input strings is 'key=value', the list is parsed
' The key for the first occurrence of sVal is returned
dim iCurrentValue as integer
dim iListItems as integer
iListItems = listcount( lsList() )
dim cLine as string
' preset a default return string
hGetKeyForValueAsString() = "Error: No matching KEY found for VALUE"
'///+- scan through a list to find an entry that matches sKey. Return the Key.
for iCurrentValue = 1 to iListItems
cLine = lsList( iCurrentValue )
if( instr( cLine , sVal ) <> 0 ) then
hGetKeyForValueAsString() = hGetKeyForPairAsString( cLine )
iCurrentValue = iListItems + 1
end if
next iCurrentValue
'///+- Return the key from the first matching value
'///
end function
'*******************************************************************************
function hGetKeyForValueAsInt( lsList() as string, sVal as string ) as integer
'///Retrieve the KEY for a known VALUE from a key=value pair
'///About "KEY"-functions:
'///These functions are used whenever
'///+ data is to be processed that is stored in a key=value format.
'///+ They handle a single string or a list of strings
'///+ to e.g. isolate a key, a value or to just retrieve the pair.
'///Prerequisite: List compatible to listfuncs, known VALUE for pair
'///Input:
'///
'///+- List of KEY=VALUE pairs (string)
'///+- VALUE (string)
'///
'///+- Absolute match required.
'///
'///
'///Returns:
'///
'///+- KEY (integer)
'///
'///Description:
'///
'///+- Use hgetKeyForValueAsString, convert result to integer, return it.
hGetKeyForValueAsInt() = val( hGetKeyForValueAsString( lsList() , sVal ) )
'///
end function
'*******************************************************************************
function hGetIndexForKeyAsInt( lsList() as string, sKey as string ) as integer
'///Search a list of key=value pairs for a key and return its index
'///About "KEY"-functions:
'///These functions are used whenever
'///+ data is to be processed that is stored in a key=value format.
'///+ They handle a single string or a list of strings
'///+ to e.g. isolate a key, a value or to just retrieve the pair.
'///Prerequisite: List compatible to listfuncs, known VALUE for pair
'///Input:
'///
'///+- List of KEY=VALUE pairs (string)
'///+- KEY to search for (string)
'///
'///Returns:
'///
'///+- Index of the KEY in the list (integer)
'///
'///+- 0 if not found
'///+- Any number > 0 and ≤ listcount( List() )
'///
'///
'///Description:
'///
dim iItem as integer
dim cComp as string
hGetIndexForNamedKeyAsInt() = 0
' Scan through the list and look for sKey. If found, return the Value
' (everything to the right of the '=')
'///+- Scan through the list for the KEY
for iItem = 1 to listcount( lsList() )
if( instr( lsList( iItem ) , sKey ) <> 0 ) then
'///+- if found, perform reverse checking
cComp = hGetKeyforValueAsString( lsList( iItem ) )
'///+- get the index of the item
if( sKey = cComp ) then
hGetIndexForKeyAsInt() = iItem
iItem = listcount( lsList() ) + 1
endif
endif
next iItem
'///+- Return the index
'///
end function
'*******************************************************************************
function keycompare( found as string, expected as string, sKey as string, optional cBugID as string) as boolean
'///Function to compare two keys with each other
'///Deprecated, do not use
if ( isMissing( cBugID ) ) then
cBugID = ""
endif
if ( lcase(found) = lcase(expected) ) then
printlog( " * '" & sKey & "': ok" )
keycompare = true
else
warnlog( "#" + cBugID + "# Control has incorrect value: '" & sKey & "'")
printlog( " > Found...: '" & found & "'" )
printlog( " > Expected: '" & expected & "'" )
keycompare = false
endif
end function