'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 : Functions for manipulation of strings
'*
'\******************************************************************************
function hRemoveLineBreaks( cString as string ) as string
dim myString as string : myString = cString
myString = hStringReplaceChar( myString, CHR$(09), " " )
myString = hStringReplaceChar( myString, CHR$(13), " " )
myString = hStringReplaceChar( myString, CHR$(10), "" )
hRemoveLineBreaks() = myString
end function
'*******************************************************************************
function hCompareSubStrings( cRef as string, cSub as string ) as integer
'///
Find substring in a reference string
'///Used to determine that we are on "The first doc!"
'///Parameter(s):
'///
'///+- Term to search for (string)
'///+- Term to be searched (string)
'///
'///Returns:
'///
'///+- Errorcode (integer)
'///
'///+- -1: Invalid parameter(s)
'///+- 0: Strings do not match
'///+- 1: Term is exact match
'///+- 2: Term is a substring
'///
'///
'///Description:
'///
const CFN = "hCompareSubStrings::"
const RETVAL_INVALID_PARAMETER = -1
const RETVAL_MATCH_NONE = 0
const RETVAL_MATCH_EXACT = 1
const RETVAL_MATCH_SUBSTRING = 2
'///+- Test function parameters
if ( ( cRef = "" ) or ( cSub = "" ) ) then
warnlog( CFN & "invalid parameter(s): Empty string passed." )
hCompareSubStrings() = RETVAL_INVALID_PARAMETER
exit function
endif
dim irc as integer
'///+- Test if we have a substring
if ( instr( cRef, cSub ) ) then
irc = RETVAL_MATCH_SUBSTRING
else
irc = RETVAL_MATCH_NONE
endif
'///+- Test if we have an exact match
if ( irc = RETVAL_MATCH_SUBSTRING ) then
if ( ( cRef = cSub ) and ( len( cRef ) = len( cSub ) ) ) then
irc = RETVAL_MATCH_EXACT
endif
endif
if ( GVERBOSE ) then
select case irc
case RETVAL_MATCH_NONE : printlog( CFN & "No matching substring found" )
case RETVAL_MATCH_EXACT : printlog( CFN & "Strings are identical" )
case RETVAL_MATCH_SUBSTRING : printlog( CFN & "String is substring" )
end select
endif
hCompareSubStrings() = irc
'///
end function
'******************************************************************************
function hGetDirTreeLevel( cFullPath as string ) as integer
'///Count the numbers of pathseparators in a path-string
'///Used to find the level of current directory within the directory tree.
'///+The function prints a warning when no pathseparators were found
'///Parameter(s):
'///
'///+- Path (string) with no trailing pathseparator
'///
'///Returns:
'///
'///+- Number of Pathseparators within the string (integer)
'///
'///+- 0 = failure
'///+- > 0 = level
'///
'///
'///Description:
'///
const CFN = "hGetDirTreeLevel::"
dim iCurrentChar as integer
dim cCurrentChar as string
dim iSeparatorCount as integer : iSeparatorCount = 0
'///+- Walk through the string
'///
for iCurrentChar = 1 to len( cFullPath )
'///+- Get the next character
cCurrentChar = mid( cFullPath , iCurrentChar , 1 )
'///+- If it is a separtator, increase the counter
if ( cCurrentChar = gPathSigne ) then iSeparatorCount = iSeparatorCount + 1
next iCurrentChar
'///
'///+- Print a warning if no separators were found
if ( iSeparatorCount = 0 ) then
warnlog( CFN & "Did not find any separators in given string: " & cFullPath )
endif
'///
hGetDirTreeLevel() = iSeparatorCount
end function
'*******************************************************************************
function hGetStringFromStaticTextField( oControl as object ) as string
use "global\tools\includes\optional\t_accels.inc"
'///Get the string from a static textfield
'///Static textfields like those in the document properties dialog are
'///+ in certain places designed in a way that the string can be selected
'///+ and copied to the clipboard. This has been introduced with SRC680m212
'///+ (9156). This function uses keyboard shortcuts for "Select All"
'///+ and "Copy" to get the string into the clipboard as .uno.Copy
'///+ is not enabled.
'///Parameter(s):
'///
'///+- Name of the control (Object)
'///
'///+- The object must exist in the current context
'///
'///
'///Returns:
'///
'///+- Content of the field (String)
'///
'///+- Blank if string is empty
'///
'///
const CFN = "hGetStringFromStaticTextField::"
dim brc as boolean 'a multi purpose boolean returnvalue
dim cSelectAll as string
dim cCopy as string
dim cText as string
if ( GVERBOSE ) then printlog( CFN & "Enter" )
'///Description:
'///
'///+- Verify that the object exists
'///+- Get the accelerator for SelectAll and Copy
'///+- Execute SelectAll and Copy on control
'///+- Get the string from the clipboard
if ( oControl.exists() ) then
if ( oControl.isVisible() ) then
cSelectAll = hGetAccel( "SelectAll" )
cCopy = hGetAccel( "Copy" )
oControl.typeKeys( "" )
oControl.typeKeys( cSelectAll )
oControl.typeKeys( cCopy )
cText = getClipboardText()
if ( GVERBOSE ) then printlog( CFN & "Exit with result: " & cText )
else
ctext = ""
warnlog( CFN & "Exit: Control exists but is not visible" )
endif
else
cText = ""
warnlog( CFN & "Exit: Control does not exist in this context" )
endif
'///
hGetStringFromStaticTextField() = cText
end function
'*******************************************************************************
function hConvertStringToLong( cValue as string ) as long
'///Convert a stringvalue to long int
'///The purpose of this function is to isolate the filesize from a string
'///+ of the type "1.345 Bytes" by removing the thousands-separator
'///+ and the trailing unit. The result is then a filesize as long integer
'///+ which then can be compared to the result from the BASIC function
'///+ FileLen( FileSpec )
'///Parameter(s):
'///
'///+- String containing a long integer value (String)
'///
'///+- No floating point values allowed
'///+- Numeric value must be at the beginning of the string (no leading characters/spaces)
'///+- Negative values are allowed
'///+- Leading "+" is not allowed
'///
'///
'///Returns:
'///
'///+- Value of the string as long integer (Long)
'///
'///+- Thousands separator (. or ,) have been removed
'///+- Decimal separators (though not allowed) have been removed
'///
'///
const CFN = "hConvertStringToLong::"
const ONE_CHARACTER = 1
if ( GVERBOSE ) then printlog( CFN & "Enter with option: " & cValue )
dim iLen as integer : iLen = len( cValue )
dim iChar as integer
dim cChar as string
dim cStringValue as string : cStringValue = ""
'///Description:
'///
'///+- Walk through the single chars of the string
'///
for iChar = 1 to iLen
'///+- Get the current character
cChar = mid( cValue , iChar , ONE_CHARACTER )
'///+- Copy valid characters to temporary string, drop invalid, exit on first space or other character
select case cChar
case "-" : cStringValue = cStringValue & cChar
case "1" : cStringValue = cStringValue & cChar
case "2" : cStringValue = cStringValue & cChar
case "3" : cStringValue = cStringValue & cChar
case "4" : cStringValue = cStringValue & cChar
case "5" : cStringValue = cStringValue & cChar
case "6" : cStringValue = cStringValue & cChar
case "7" : cStringValue = cStringValue & cChar
case "8" : cStringValue = cStringValue & cChar
case "9" : cStringValue = cStringValue & cChar
case "0" : cStringValue = cStringValue & cChar
case else: ' do nothing
end select
next iChar
'///
if ( GVERBOSE ) then printlog( CFN & "Exit with value: " & cStringValue )
'///+- Convert string to long integer and return to calling function
hConvertStringToLong() = val( cStringValue )
'///
end function
'*******************************************************************************
function hStringReplace( cString as string, search_string as string, replace_with as string ) as string
const CFN = "hStringReplace(): "
dim search_string_position as string
dim search_string_found as boolean : search_string_found = true
dim len_search_string as integer : len_search_string = len( search_string )
dim len_replace_with as integer : len_replace_with = len( replace_with )
dim myString as string : myString = cString
if ( GVERBOSE ) then printlog( CFN & "Replace all <" & search_string & "> with <" & replace_with & "> in <" & myString & ">" )
if ( not instr( replace_with, search_string ) and len_search_string >= len_replace_with ) then
do while( search_string_found )
search_string_position = instr( myString, search_string )
if ( search_string_position > 0 ) then
mid( myString, search_string_position, len( search_string ), replace_with )
else
search_string_found = false
endif
loop
else
warnlog( CFN & "Function used incorrectly" )
warnlog( CFN & "Replace all <" & search_string & "> with <" & replace_with & "> in <" & myString & ">" )
warnlog( CFN & "The new string must be of equal length or shorter than the string to be replaced" )
warnlog( CFN & "The new string may not contain the string to be replaced (e.g. replace 'a' with 'ha' is not allowed)" )
endif
if ( GVERBOSE ) then printlog( CFN & "Return string is <" & myString & ">" )
hStringReplace() = myString
end function