From 86319fd1c32ab1accd109e0bfa5b79cfc6ba1446 Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Wed, 30 Jan 2019 00:39:43 +0000 Subject: [PATCH] That seems to fix it! --- src/io/io.c | 6 +++--- src/memory/consspaceobject.c | 21 +++++++++++---------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/io/io.c b/src/io/io.c index 1ff53db..e7554ec 100644 --- a/src/io/io.c +++ b/src/io/io.c @@ -260,11 +260,11 @@ int index_of( char c, char *s ) { char *trim( char *s ) { int i; - for ( i = strlen( s ); ( isblank( s[i] ) || iscntrl( s[i] ) ) && i > -1; + for ( i = strlen( s ); ( isblank( s[i] ) || iscntrl( s[i] ) ) && i >= 0; i-- ) { s[i] = ( char ) 0; } - for ( i = 0; isblank( s[i] ) && s[i] != 0; i++ ); + for ( i = 0; ( isblank( s[i] ) || iscntrl( s[i] ) ) && s[i] != 0; i++ ); return ( char * ) &s[i]; } @@ -313,7 +313,7 @@ static size_t write_meta_callback( char *string, size_t size, size_t nmemb, if ( offset != -1 ) { s[offset] = ( char ) 0; - char *name = s; + char *name = trim( s ); char *value = trim( &s[++offset] ); wchar_t *wname = calloc( strlen( name ), sizeof( wchar_t ) ); wchar_t *wvalue = calloc( strlen( value ), sizeof( wchar_t ) ); diff --git a/src/memory/consspaceobject.c b/src/memory/consspaceobject.c index 0baba69..aa1cece 100644 --- a/src/memory/consspaceobject.c +++ b/src/memory/consspaceobject.c @@ -323,19 +323,18 @@ struct cons_pointer make_write_stream( URL_FILE * output, } /** - * Return a lisp keyword representation of this wide character string. + * Return a lisp keyword representation of this wide character string. In keywords, + * I am accepting only lower case characters and numbers. */ struct cons_pointer c_string_to_lisp_keyword( wchar_t *symbol ) { struct cons_pointer result = NIL; - for (int i = 0; symbol[i] != '\0'; i++) { - if(iswalpha(symbol[i] && !iswlower(symbol[i]))) { - symbol[i] = towlower(symbol[i]); - } - } + for ( int i = wcslen( symbol ) -1; i >= 0; i-- ) { + wchar_t c = towlower(symbol[i]); - for ( int i = wcslen( symbol ); i > 0; i-- ) { - result = make_keyword( symbol[i - 1], result ); + if (iswalnum(c) || c == L'-') { + result = make_keyword( c, result ); + } } return result; @@ -347,8 +346,10 @@ struct cons_pointer c_string_to_lisp_keyword( wchar_t *symbol ) { struct cons_pointer c_string_to_lisp_string( wchar_t *string ) { struct cons_pointer result = NIL; - for ( int i = wcslen( string ); i > 0; i-- ) { - result = make_string( string[i - 1], result ); + for ( int i = wcslen( string ) - 1; i >= 0; i-- ) { + if (iswprint(string[i]) && string[i] != '"') { + result = make_string( string[i], result ); + } } return result;