# $Header: /home/cvsroot/tcldb/ucodb/Tlib/stringFix2,v 1.1.1.1 1996/10/12 01:08:25 de Exp $
# tcl procs saved on Sun Sep 03 16:19:09 PDT 1995

proc stringFix2 {strg mode} {

# Dir is either in or out.
# If in (from dbase) then turn dbl sgl quo into sgl quo
# if out (to dbase) then turn dbl quo into dbl sgl quo and
# turn sgl quo into dbl sgl




# 	In either case we translate the '' into ' before proceeding

	set err [regsub -all "''" $strg \' strg]
	if {$err} {
	}

#	If outbound, we translate all embedded quotes into dblsgls

	if {$mode == "out"} {

        set err [regsub -all \" $strg "''" strg]
        if {$err} {
        } 

        set err [regsub -all \' $strg "''" strg]
	if {$err} {
	}

	}

#	If this string is framed in curlies then trim them.  Otherwise leave
#	them alone.

	set ce [expr [clength $strg] -1]
	if {([crange $strg 0 0] == "\{" ) && ([crange $strg $ce $ce] == "\}" )} {

#	don't trim double curlies from end of list w/embedded list!
#	just clip one char off each end
#	set strg "[string trimleft [string trimright $strg \}] \{]"

	if {[expr $ce - 1] < 1} {
		set strg ""
	} else {
		set strg "[crange $strg 1 [expr $ce - 1]]"
	}

	}

#	now trim trailing CR and spaces

	set strg [string trimright $strg \n]
	set strg [string trimright $strg]

	return $strg
	
}

