Page Blocks

Hosting sponsored by:

Point In Space

 

API: Cnfg

Filename:
fwpCnfg_splitTabs.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_splitTabs (Tag)

Description

Accepts a string of items delimited with tabs, and splits the text at the tabs to create a Lasso array. Optionally, it can normalize tab usage to one tab between text items to convert multiple tabs used to align columns of text in a file.

The normalizing function is rather useful on its own, so a -withoutSplit option is available to prevent the split, and the data is returned as a string with normalized tab delimiting.

Syntax

varName = fwpCnfg_splitTabs: varName;

varName = fwpCnfg_splitTabs: varName, -withoutSplit;

Parameters & Member Tags

list (unnamed) = required : literal string data or a string variable.

-withoutSplit = optional : include this param if the text is not to be split into an array.

-removeExtraTabs = optional : include this param if the text includes multiple tabs between data items that should be normalized to a single tab before splitting.

Examples

#cnfgData = fwpCnfg_splitTabs: #cnfgData;

This code:

#cnfgData = fwpCnfg_splitTabs: 'red\tyellow\tblue\t\tgreen';

would return

array: (red), (yellow), (blue), (), (green)

And this code:

#cnfgData = fwpCnfg_splitTabs: 'red\tyellow\tblue\t\t\t\tgreen';

would return

array: (red), (yellow), (blue), (green)

Source Code

View in separate window

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

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

    {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=            This routine converts a tab separated list into an array }

    {maintvsrn=        1.2.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.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,
                    added -despace
                    added data type error trap }

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

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

define_tag:'fwpCnfg_splitTabs', -priority='replace',
    -required='list';

//    -removeExtraTabs (-despace deprecated)
//    -withoutSplit (-nosplit deprecated)

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

    local:
        'configData'         = #list,
        'removeExtraTabs'     = false,
        'withoutSplit'         = false;

    (params->find:'-removeExtraTabs') || (params->find:'-despace')
        ? #removeExtraTabs = true;

    (params->find:'-withoutSplit') || (params->find:'-nosplit')
        ? #withoutSplit = true;

    if: #configData; 
        if:    ((#configData->type != 'string') && (#configData->type != 'bytes'));
            $fw_error->(insert:'5201'='fwpCnfg_splitTabs');
            $fw_debug ? $fw_apiError->(insert:'5245'=(#list->type));
            $fw_debug ? $fw_tagTracer->(add:'fwpCnfg_splitTabs', -ERROR = 'input was not a string or bytes');
            $fw_criticalLog ? log_critical:'pbError : input to fwpCnfg_splitTabs was not a string or bytes';
        else;
    
            #removeExtraTabs        
                ? #configData = (string_replaceRegExp:
                    #configData,
                    -find     = '\\t+',
                    -replace = '\\t');
    
            !#withoutSplit
                ? #configData=(#configData->split:'\t');
    
            return: #configData;

        /if;
    /if;
/define_tag;
?>

© 2002-2012, pageblocks.org