/* string_functions.c Part of ForthBASIC, the BASIC interpreter and menuing system of POWER X Y This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "stack.h" #include "datatypes.h" // Converts a string to uppercase // ( in -- out ) void basicfn_ucase(void) { unsigned char* tos=stackptr; unsigned char c; unsigned char t=*tos++; if(t==BTYPE_U8) { c=*tos; if(c>='a' && c<='z') *tos=c-('a'-'A'); } else if(t==BTYPE_RAWSTR || t==BTYPE_NKSTR || t==BTYPE_437STR) { int L= *(int *) tos; tos += sizeof(int); while(L) { c=*tos; if(c>='a' && c<='z') *tos=c-('a'-'A'); if(c>=0x80) { if(t==BTYPE_NKSTR) { if(c>=0xF0 && c<0xFF) { tos++; L--; } // Japanese else if(c==0x84) *tos=0x8C; // a ' else if(c==0x85) *tos=0x8D; // e ' else if(c==0x86) *tos=0x8E; // i ' else if(c==0x87) *tos=0x9C; // o ' else if(c==0x88) *tos=0x9D; // u ' else if(c==0x94) *tos=0x9E; // a ` else if(c==0x95) *tos=0xAC; // e ` else if(c==0x96) *tos=0xAD; // i ` else if(c==0x97) *tos=0xAE; // o ` else if(c==0x98) *tos=0xBC; // u ` else if(c==0xA4) *tos=0xBD; // a " else if(c==0xA5) *tos=0xBE; // e " else if(c==0xA6) *tos=0xCC; // i " else if(c==0xA7) *tos=0xCD; // o " else if(c==0xA8) *tos=0xCE; // u " else if(c==0xB8) *tos=0xDC; // a ^ else if(c==0xC8) *tos=0xDD; // e ^ else if(c==0xC7) *tos=0xDE; // i ^ else if(c==0xC6) *tos=0xEC; // o ^ else if(c==0xD8) *tos=0xED; // u ^ else if(c==0x8F) *tos=0xE9; // ae else if(c==0xB7) *tos=0xEE; // c , else if(c==0xBF) *tos=0xAF; // y " else if(c==0xB4) *tos=0xEF; // a ~ else if(c==0xB5) *tos=0xDF; // n ~ else if(c==0xB6) *tos=0xCF; // o ~ } else if(t==BTYPE_437STR) { // TODO } } tos++; L--; } } } // Converts katakana to hiragana // ( in -- out ) void basicfn_hiragana(void) { unsigned char* tos=stackptr; unsigned char c; unsigned char t=*tos++; if(t==BTYPE_NKSTR) { int L= *(int *) tos; tos += sizeof(int); while(L) { if(c>=0xF8 && c<=0xFE) *tos=c-0x08; tos++; L--; } } } // Converts hiragana to katakana // ( in -- out ) void basicfn_katakana(void) { unsigned char* tos=stackptr; unsigned char c; unsigned char t=*tos++; if(t==BTYPE_NKSTR) { int L= *(int *) tos; tos += sizeof(int); while(L) { if(c>=0xF0 && c<=0xF6) *tos=c+0x08; tos++; L--; } } }