CFLib.org – Common Function Library Project

getProfileSectionsUTF8(iniPath)

Last updated July 27, 2012

author

Reinhard Jung

Version: 1 | Requires: CF9 | Library: CFMLLib

Description:
It supports to translate any unicode-based language instead of using GetProfileSections() which doesn't support Unicode (UTF-8). See http://help.adobe.com/en_US/ColdFusion/10.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-6cff.html

Return Values:
Struct keyed by profile section, the values being comma-delimited lists of section entries

Example:

<cfdump var="#getProfileSectionsUTF8("/path/to/my.ini")#">

Parameters:

Name Description Required
iniPath Full path to ini file to parse. Yes

Full UDF Source:

/**
 * UTF8-aware implementation of getProfileSections()
 * * version 0.1 by Reinhard Jung
 * * version 1.0 by Adam Cameron - convert into single UDF &amp; mirror usage of getProfileSections()
 * * version 1.1 by Adam Cameron (with help from Simon Baynes).  Removing debug code; correcting fileClose() behaviour
 * 
 * @param iniPath      Full path to ini file to parse. (Required)
 * @return Struct keyed by profile section, the values being comma-delimited lists of section entries 
 * @author Reinhard Jung (reinhard.jung@gmail.com) 
 * @version 1, July 27, 2012 
 */
function getProfileSectionsUTF8(iniPath) {
    var iniFile            = "";
    var line            = "";
    var profileSections = structNew();
    var thisSection        = "";

    try {
        iniFile = fileOpen(iniPath, "read", "UTF-8");
        line    = "";
        
        while (!fileIsEOF(iniFile)) {
            line = FileReadLine(iniFile);

            findSection = reFind("^\s*\[([^\]]+)\]", line, 1, true);    // eg: [sectionName]
            if (arrayLen(findSection.pos) gt 1){    // we're in a section
                thisSection = mid(line, findSection.pos[2], findSection.len[2]);
                profileSections[thisSection] = "";
                continue;
            }

            if (listLen(line, "=")){    // ie: not empty
                profileSections[thisSection] = listAppend(profileSections[thisSection], listFirst(line, "="));
            }            
        }
    }
    finally {
        if (iniFile != ""){    // assuming it's not its default value, it's safe to assume it's a file handle
            fileClose(iniFile);
        }
    }
    return profileSections;
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson