text in fields (CR/LF, CR, LF) which is correct?
Dar Scott
dsc at swcp.com
Sat Aug 31 12:45:01 EDT 2002
On Saturday, August 31, 2002, at 11:03 AM, J. Landman Gay wrote:
> For example, in Kee's problem, I'd think that this would work okay:
>
> get data from database, put it in a variable
> replace database line endings with returns in the variable
> put variable into a field
>
> It seems to me that the above would convert all line endings to
> machine-specific line endings without any manual manipulation, and
> would go cross-platform without any changes. When the data needs
> to go back to the database:
>
> put the field text into a variable
> replace returns with database-specific line endings
> send variable back to the database
>
> What am I missing? Doesn't this work?
Yes, with the caveat that "return" here means the Rev constant
"return" and not the more common meaning of ASCII Carriage Return,
numToChar(13).
This also has the advantage of addressing the complementary problem
of writing back to the DB.
However, this requires that one know the "database-specific line
endings" beforehand and adapt should they change (over time, or
across platforms or DB). Of course, if there is a requirement to
write back out to the DB then it must be used. Also, this does not
address the general foreign file or stream or message or clipboard
concern in cases where Rev text I/O does not work or does not
apply. Also, it might not be robust in handling variations.
The Modified Nethery Function is shown below:
function adjustedLineEndInput thetext
replace (numtochar(13) & numtochar(10)) with numtochar(13) in thetext
replace numtochar(13) with numtochar(10) in thetext
return thetext
end adjustedLineEndInput
Takes text from almost any environment and converts it to internal
Rev text.
The word "Input" is in the name to emphasize that it only does half
of what Jacqueline's scheme does. (If lineEnd were a constant, the
function could use that for numToChar(10) in the second replace.
If asciiCR and asciiLF were constants, they could be used in the
rest of the function.)
This does two replaces and Jacqueline's does one. I don't think
one more replace is a high price.
(The Modified Nethery Function beats the function I had been using
which had three replaces, but does the same thing.)
Dar Scott
More information about the use-livecode
mailing list