Changeset 578


Ignore:
Timestamp:
12/22/2011 15:34:47 (5 months ago)
Author:
blee
Message:

Support literal backslashes, tabs, and new lines.

See #153

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libfiledb.sh.in

    r577 r578  
    3131# 
    3232# The on-disk storage format uses the tab character as the field delimiter 
    33 # and the new line character as the record delimiter.  Tab characters are 
    34 # accepted in keys and values. 
     33# and the new line character as the record delimiter.  Tab characters and 
     34# new lines are accepted in both keys and values and recorded as "\t" and 
     35# "\n" respectively. 
    3536 
    3637# Purpose: Load a filedb into an array 
     
    5455        local IFS="     " 
    5556        while read -r key value; do 
    56                 eval "`echo "${array}"`[`echo -e "${key}"`]=`echo -e "${value}"`" 
     57                eval "`echo "${array}"`[\"`echo -e "${key}"`\"]=\"`echo -e "${value}"`\"" 
    5758        done <"${filedb}" && 
    5859        return 0 
     
    7576 
    7677        local i 
     78        local line 
    7779        local key 
    7880        local value 
     
    8183        [ -v "${array}" ] && 
    8284        eval 'for i in "'"\${!${array}"'[@]}"; do 
    83                 echo "${i}" 
    84         done' | while read key; do 
    85                 eval 'value="'"\${${array}[${key}]}"'"' 
     85                i="${i//\\/\\\\}" 
     86                i="${i// 
     87/\\n}" 
     88                echo -E "${i}" 
     89        done' | while read -r key; do 
     90                eval 'value="'"\${${array}["'"'${key}'"]}"' 
     91                value="${value//\\/\\\\}" 
     92                value="${value// 
     93/\\n}" 
    8694                echo -nE "${key%%       *}" 
    8795                while [ "${key}" != "${key#*    }" ]; do 
Note: See TracChangeset for help on using the changeset viewer.