Re: problem with regexp:regexp-split

Pascal Bourguignon <[email protected]>
Newsgroups gmane.lisp.clisp.general
Message-ID <[email protected]>
> On 15 Dec 2016, at 23:55, Jean Louis <[email protected]> wrote:
> 
> Hello,
> 
> I have some problem in understanding.
> 
> (defparameter latitude "6° 45' 22.90\"    S")
> (defparameter longitude "35° 7' 23.60\"  E")
> 
> (regexp:regexp-split " " latitude)
> => ("6° " "5'" "22.90\"" "" "" "" "S")
> 
> That was my expected output for latitude, but I get problem with
> longitude:
> 
> (regexp:regexp-split " " longitude)
> => ("35° " "'" "23.60\"" "" "E")
> 
> So that is not the expected value for longitude, and I don't know what
> to do to make it happen, as I miss the number "7" there.



You also miss the 4 in the latitude, and you have superfluous spaces in the first items.

The problem you have is that your strings are converted to UTF-8 when they are passed to the C library regex(7), and the clisp regexp module is confused between the indices returned by regex(7) (which are byte indices), and characters that are decoded from UTF-8 byte sequences.

CL-USER> (setf CUSTOM:*MISC-ENCODING* charset:utf-8)
#<ENCODING CHARSET:UTF-8 :UNIX>
CL-USER> (regexp:regexp-split " " latitude)
("6° " "5'" "22.90\"" "" "" "" "S")
CL-USER> (regexp:regexp-split " " longitude)
("35° " "'" "23.60\"" "" "E")
CL-USER> 

If you convert instead the string into a 1-1 encoding, then it will work correctly:

CL-USER> (setf CUSTOM:*MISC-ENCODING* charset:iso-8859-1)
#<ENCODING CHARSET:ISO-8859-1 :UNIX>
CL-USER> (regexp:regexp-split " " latitude)
("6°" "45'" "22.90\"" "" "" "" "S")
CL-USER> (regexp:regexp-split " " longitude)
("35°" "7'" "23.60\"" "" "E")


https://sourceforge.net/p/clisp/bugs/691/
-- 
__Pascal J. Bourguignon__



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
clisp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/clisp-list
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.