Page Blocks

Hosting sponsored by:

Point In Space

 

API: Cnfg

Filename:
fwpCnfg_splitPairs.ctag

Released With:
5.0.0

Current Version:
1.2.0

Status: Active

Min Lasso Tested: 8.1.0

Max Lasso Tested: 8.5.3

Related:

Still don't get it?

Check out the talk list archives, or join and ask your questions.

Documentation Error or Request?

Email documentation corrections or comments

API Reference

fwpCnfg_splitPairs (Tag)

Description

Converts strings of first=second definitions into an array of Lasso pair data types, or into a map. Accepts either an array of first=second strings, or a string where first=second elements are delimited with line endings (\r, \n, or \r\n).

So, (array: 'car=ford', 'model=GT40', 'color=yellow')
or (string: 'car=ford\r'model=GT40\rcolor=yellow')
are acceptable as inputs.

Syntax

varName = fwpCnfg_splitPairs: varName;

Parameters & Member Tags

text (unnamed) = required : literal string or array data or variable.

-intoMap|-asMap = optional : add this param to make the result a Lasso map instead of an array of pairs.

Examples

#cnfgData = fwpCnfg_splitPairs: #cnfgData;

#cnfgData = fwpCnfg_splitPairs: #cnfgData, -intoMap;

Source Code

View in separate window

<?lassoscript
//............................................................................
//
//    pageblocks: (c) 2002-2007 http://www.pageblocks.org/
//
//............................................................................
/*

    {fileName=        fwpCnfg_splitPairs.ctag }
    {rsrcType=        tag }
    {rsrcName=        fwpCnfg_splitPairs }
    {rsrcHTTP=        www.pageblocks.org/refc/fwpCnfg_splitPairs }

    {lassoVrsnMin=    8.1.0 }
    {lassoVrsnMax=    8.5.3 }

    {author=        Greg Willits }
    {authorEmail=    subscribe to pbTalk at www.pageblocks.org/talk/ }
    {authorHTTP=    www.pageblocks.org }

    {desc=            Converts a series of first=second strings into 
                    an array of Lasso pairs. Accepts an array, or a string
                    of first=second strings delimited by EOL character(s). }

    {maintvsrn=        1.3.0 }
    {maintrelease=    5.2.0 }
    {maintdate=        2007-06-09}
    {maintauthor=    Greg Willits }
    {maintnotes=    updated debug and error handling systems,
                     changed some internal vars for better readability }

    {maintvsrn=        1.2.0 }
    {maintrelease=    5.1.5 }
    {maintdate=        2007-02-21 }
    {maintauthor=    Greg Willits }
    {maintnotes=    added -makeMap option }

    {maintvsrn=        1.1.0 }
    {maintrelease=    5.2.0 }
    {maintdate=        2007-01-02 }
    {maintauthor=    Greg Willits }
    {maintnotes=    added allowance for spaces around the = delimiters, 
                    and added allowance for lines to not have delimiters
                    in which case the pair becomes x = x }

    {maintvsrn=        1.1.0 }
    {maintrelease=    5.1.0 }
    {maintdate=        2006-05-30}
    {maintauthor=    Greg Willits }
    {maintnotes=    added tagTrace }

    {maintvsrn=        1.0.2 }
    {maintrelease=    5.0.0 b5 }
    {maintdate=        2006-02-02 }
    {maintauthor=    Greg Willits }
    {maintnotes=    doh! fixed type detection logic which didn't allow
                    for empty input }

    {maintvsrn=        1.0.1 }
    {maintrelease=    5.0.0 b5 }
    {maintdate=        2006-01-27 }
    {maintauthor=    Greg Willits }
    {maintnotes=    changed some syntax for efficiency }

    {maintvsrn=        1.0 }
    {maintrelease=    5.0.0 }
    {maintdate=        2006-01-16 }
    {maintauthor=    Greg Willits }
    {maintnotes=    initial release }

*/
//.............................................................................

define_tag:'fwpCnfg_splitPairs', -priority='replace',
    -required='pairs';

//    -asMap | -intoMap (-makemap deprecated)

    ($fw_debug >= fw_kVerbose) ? $fw_tagTracer->(add:'fwpCnfg_splitPairs');

    local:
        'configData'        = #pairs,
        'asMap'                = false,
        'thisLine'            = string,
        'pairDelimiter'        = string,
        'splitResults'        = array;

    (params->find:'-intoMap') || (params->find:'-asMap') || (params->find:'-makeMap')
        ? #asMap = true;

    #asMap
        ? #splitResults = map;

    if: #configData;

        if: ((#configData->type != 'string') && (#configData->type != 'bytes'));
            $fw_error->(insert:'5201'='fwpCnfg_splitPairs');
            $fw_debug ? $fw_apiError->(insert:'5244'=(#pairs->type));
            $fw_debug ? $fw_tagTracer->(add:'fwpCnfg_splitPairs', -ERROR = 'input was not a string or bytes');
            $fw_criticalLog ? log_critical:'pbError : input to fwpCnfg_splitPairs was not a string or bytes';
        else;

            #configData = (string_replaceRegExp: 
                #configData, 
                -find = '\\s*===\\s*',
                -replace = '===');
            #configData = (string_replaceRegExp: 
                #configData, 
                -find = '\\s*=\\s*',
                -replace = '=');
            (#configData = (fwpCnfg_splitLines:#configData));
    
            ((#configData->get:1) >> '===')
                ? (#pairDelimiter = '===')
                | (#pairDelimiter = '=');
    
            if: #asMap;
                iterate: #configData, #thisLine;
                    #thisLine >> #pairDelimiter
                        ? #splitResults->(insert: ((#thisLine->split:#pairDelimiter)->get:1)=((#thisLine->split:#pairDelimiter)->get:2))
                        | #splitResults->(insert: #thisLine = #thisLine);
                /iterate;
            else;
                iterate: #configData, #thisLine;
                    #thisLine >> #pairDelimiter
                        ? #splitResults->(insert: (pair:((#thisLine->split:#pairDelimiter)->get:1)=((#thisLine->split:#pairDelimiter)->get:2)))
                        | #splitResults->(insert: (pair: #thisLine = #thisLine));
                /iterate;
            /if;
        
            return: #splitResults;
        /if;
    else;
        ($fw_debug >= fw_kChatty) ? $fw_tagTracer->(add:'fwpCnfg_splitPairs', -status = 'input was empty');
    /if;
/define_tag;
?>



© 2002-2012, pageblocks.org