This project has moved. For the latest updates, please go here.
1
Vote

pfc_n_cst_string->of_getkeyvalue issue

description

//pfcapsrv.pbl->pfc_n_cst_string->of_getkeyvalue() does not return the key value if it is in the middle of the string issue encountered while traversing a treeview to display data in tabs


//to replicate use these values
as_source = 'Key=1031; ExpandName=; DataStore=1; LabelSeparator=\;'
as_keyword = 'DataStore'
//this should return '1' but its does not.
ls_keyvalue = ''

//reason for failure is
// this line determines the position of the as_keyword in as_source making li_keyword = 24
li_keyword = Pos (Lower(as_source), Lower(as_keyword))

//this line trims the as_source up to the first occurrence of the as_keyword making as_source = '=1; LabelSeparator=\;'
as_source = LeftTrim(RightA(as_source, LenA(as_source) - (li_keyword + LenA(as_keyword) - 1)))

// but it does not adjust the value of li_keyword to the next position of as_keyword in as_source after the trim
// full solution to my encountered issue is below

//////////////////////////////////////////////////////////////////////////////
//
// Function: of_GetKeyValue
//
// Access: public
//
// Arguments:
// as_source The string to be searched.
// as_keyword The keyword to be searched for.
// as_separator The separator character used in the source string.
//
// Returns: string
// The value found for the keyword.
// If no matching keyword is found, an empty string is returned.
// If any argument's value is NULL, function returns NULL.
//
// Description: Gets the value portion of a keyword=value pair from a string.
//
//////////////////////////////////////////////////////////////////////////////
//
// Revision History
//
// Version
// 5.0 Initial version
// 6.0.01 Make function find only an exact match of the keyword
// 12.5 adjust the value of li_keyword to the next position of as_keyword in as_source after the trim
//
//////////////////////////////////////////////////////////////////////////////
//
/*
  • Open Source PowerBuilder Foundation Class Libraries
    *
  • Copyright (c) 2004-2005, All rights reserved.
    *
  • Redistribution and use in source and binary forms, with or without
  • modification, are permitted in accordance with the GNU Lesser General
  • Public License Version 2.1, February 1999
    *
  • http://www.gnu.org/copyleft/lesser.html
    *
  • ====================================================================
    *
  • This software consists of voluntary contributions made by many
  • individuals and was originally based on software copyright (c)
  • 1996-2004 Sybase, Inc. http://www.sybase.com. For more
  • information on the Open Source PowerBuilder Foundation Class
  • Libraries see http://pfc.codexchange.sybase.com
    */
    //
    //////////////////////////////////////////////////////////////////////////////
boolean lb_done=false
integer li_keyword, li_separator, li_equal
string ls_keyvalue, ls_source, ls_exact

//Check parameters
If IsNull(as_source) or IsNull(as_keyword) or IsNull(as_separator) Then
string ls_null
SetNull (ls_null)
Return ls_null
End If

//Initialize key value
ls_keyvalue = ''

do while not lb_done
li_keyword = Pos (Lower(as_source), Lower(as_keyword))
if li_keyword > 0 then
    ls_source = as_source
    as_source = LeftTrim(Right(as_source, Len(as_source) - (li_keyword + Len(as_keyword) - 1)))

    //adjust the value of  li_keyword to the next position of as_keyword in as_source after the trim      
            li_keyword = Pos (Lower(as_source), Lower(as_keyword))

            // see if this is an exact match.  Either the match will be at the start of the string or
    // the match will be after a separator character.  So check for both cases
    li_equal = li_keyword - len(as_separator)
    If li_equal > 0 Then
        // not the start so see if this is a compound occurance separated by the separator string
        ls_exact = mid(ls_source, li_equal, len(as_separator))  
        If ls_exact <> as_separator Then
            // not the separator string so continue looking
            Continue
        End IF
    End If

    if Left(as_source, 1) = "=" then
        li_separator = Pos (as_source, as_separator, 2)
        if li_separator > 0 then
            ls_keyvalue = Mid(as_source, 2, li_separator - 2)
        else
            ls_keyvalue = Mid(as_source, 2)
        end if
        ls_keyvalue = Trim(ls_keyvalue)
        lb_done = true
    end if
else
    lb_done = true
end if
loop

return ls_keyvalue

comments