⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unicode.c

📁 open source bios with linux platform, very good and can be reused.
💻 C
📖 第 1 页 / 共 3 页
字号:
/* *  linux/fs/hfsplus/unicode.c * * Copyright (C) 1999-2000  Brad Boyer (flar@pants.nu) * This file may be distributed under the terms of the GNU Public License. * * The routines found here convert hfs-unicode string into ascii Strings * and vice versa.  And the correct comparison between Strings. */#include "openbios/config.h"#include "libhfsp.h"#include "unicode.h"/* ISO-8859-1 -> unicode */static intasc2uni( unsigned char *ustr, const char *astr, int maxlen ){	int len;		if( maxlen <= 0 )		return 0;	for( len=0; *astr && len < maxlen-1 ; astr++, len++ ) {		*ustr++ = 0;		*ustr++ = *astr;	}	ustr[0] = ustr[1] = 0;	return len;}/* unicode -> ISO-8859-1 */static intuni2asc( char *astr, const unsigned char *ustr, int ustrlen, int maxlen ){	int len;		if( maxlen <= 0 )		return 0;		for( len=0; ustrlen-- > 0 && len < maxlen-1 ; ustr += 2 ) {		/* might be unrepresentable (or too complicated for us) */		if( ustr[0] || !ustr[1] )			continue;		*astr++ = ustr[1];		len++;	}	*astr = 0;	return len;}intunicode_asc2uni( hfsp_unistr255 *ustr, const char* astr ){	return ustr->strlen = asc2uni( (u8*)ustr->name, astr, 255 );}intunicode_uni2asc(char *astr, const hfsp_unistr255 *ustr, int maxlen){	return uni2asc( astr, (u8*)ustr->name, ustr->strlen, maxlen );}/* The following code is almost as published by Apple, only   small modifications where made to match some linux styles ...fastUnicodeCompare - Compare two Unicode strings; produce a relative ordering*/static const UInt16 gLowerCaseTable[];SInt32 fast_unicode_compare ( const hfsp_unistr255 *ustr1, 			      const hfsp_unistr255 *ustr2){    register UInt16     c1,c2;    register SInt32	diff;    register UInt16     temp;    register UInt16	length1 = ustr1->strlen;    register UInt16	length2 = ustr2->strlen;    register const UInt16* lowerCaseTable = gLowerCaseTable;    register UInt16*	str1 = ustr1->name;    register UInt16*	str2 = ustr2->name;    while (1) {        //  Set default values for c1, c2 in case there are no more valid chars        c1 = c2 = 0;        //  Find next non-ignorable char from str1, or zero if no more        while (length1 && c1 == 0) {            c1 = *(str1++);            --length1;            if ((temp = lowerCaseTable[c1>>8]) != 0)        //  is there a subtable                                                            //  for this upper byte?                c1 = lowerCaseTable[temp + (c1 & 0x00FF)];  //  yes, so fold the char        }        //  Find next non-ignorable char from str2, or zero if no more        while (length2 && c2 == 0) {            c2 = *(str2++);            --length2;            if ((temp = lowerCaseTable[c2>>8]) != 0)        //  is there a subtable                                                            //  for this upper byte?                c2 = lowerCaseTable[temp + (c2 & 0x00FF)];  //  yes, so fold the char        }	diff = c2-c1;        if (diff)       //  found a difference, so stop looping            break;        if (c1 == 0)        //  did we reach the end of both strings at the same time?            return 0;       //  yes, so strings are equal    }    return diff;}/*  The lower case table consists of a 256-entry high-byte table followed by    some number of 256-entry subtables. The high-byte table contains either an    offset to the subtable for characters with that high byte or zero, which    means that there are no case mappings or ignored characters in that block.    Ignored characters are mapped to zero. */static const UInt16 gLowerCaseTable[] = {    // High-byte indices ( == 0 iff no case mapping and no ignorables )    /* 0 */ 0x0100, 0x0200, 0x0000, 0x0300, 0x0400, 0x0500, 0x0000, 0x0000,            0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    /* 1 */ 0x0600, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,            0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    /* 2 */ 0x0700, 0x0800, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,            0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    /* 3 */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,            0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    /* 4 */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,            0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    /* 5 */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,            0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    /* 6 */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,            0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    /* 7 */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,            0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    /* 8 */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,            0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    /* 9 */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,            0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    /* A */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,            0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    /* B */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,            0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    /* C */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,            0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    /* D */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,            0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    /* E */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,            0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    /* F */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,            0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0900, 0x0A00,    // Table 1 (for high byte 0x00)    /* 0 */ 0xFFFF, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,            0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F,    /* 1 */ 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,            0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F,    /* 2 */ 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027,            0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,    /* 3 */ 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,            0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,    /* 4 */ 0x0040, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,            0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -