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

📄 localemethod.c

📁 有关j2me的很好的例子可以研究一下
💻 C
字号:
/* * @(#)localeMethod.c	1.9 01/05/11 @(#) * Copyright (c) 1999-2001 Sun Microsystems, Inc. All Rights Reserved. * * This software is the confidential and proprietary information of Sun * Microsystems, Inc. ("Confidential Information").  You shall not * disclose such Confidential Information and shall use it only in * accordance with the terms of the license agreement you entered into * with Sun. * * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING * THIS SOFTWARE OR ITS DERIVATIVES. */#include "global.h"#include "defaultLCDUI.h"#include "conv.h"/* * A locale methods definition. */typedef struct _LcMethodsRec {    char               *locale;    char               *encoding;    LcConvMethods       conv;} LcMethodsRec, *LcMethods;static LcMethods lc = NULL;/* * Initialize a LcMethods for the current system locale. */void initLocaleMethod(){    char *locale = NULL, *encoding = NULL;    LcConvMethods conv = NULL;    static int isCalled = 0;    /* return if it's already called */    if (isCalled) {        return;    }    /* set isCalled to avoid another call */    isCalled = 1;    /* get the current system locale info that midp supports */    getLocaleInfo(&locale, &encoding);    /* both locale and encoding have to be returned */    if (!locale || !encoding) {        return;    }    /* find a converter for the encoding */    conv = getLcConvMethods(encoding);    if (!conv) {        return;    }    lc = (LcMethods) malloc(sizeof(LcMethodsRec));    lc->locale   = locale;    lc->encoding = encoding;    lc->conv     = conv;}void finalizeLocaleMethod(){    if (lc != NULL) {        free(lc);        lc = NULL;    }}/* * Return 1 if the locale support is available */intisLocaleSupported(){    return (lc) ? 1 : 0;}/* * Return the encoding name. */char *getLocaleEncoding(){    if (lc) {        return lc->encoding;    }    return "ISO8859_1";}/* * Return the locale name. */char *getLocaleName(){    if (lc) {        return lc->locale;    }    /* The MIDP spec says that the locale name is NULL by default. */    return NULL;}/* * Convert the Unicode string into the native represented format. */int unicodeToNative(const unicode *ustr, int ulen, unsigned char *bstr, int blen){    if (lc && lc->conv) {        return lc->conv->unicodeToNative(ustr, ulen, bstr, blen);    } else {        ulen = (blen < ulen) ? blen : ulen;        blen = ulen;        while (--blen >= 0) {            bstr[blen] = (char) ustr[blen];        }        return ulen;    }}/* * Convert the native string into the Unicode format. */int nativeToUnicode(const unsigned char *bstr, int blen, unicode *ustr, int ulen){    if (lc && lc->conv) {        return lc->conv->nativeToUnicode(bstr, blen, ustr, ulen);    } else {        blen = (ulen < blen) ? ulen : blen;        ulen = blen;        while (--ulen >= 0) {            ustr[ulen] = (unicode) bstr[ulen];        }        return blen;    }}

⌨️ 快捷键说明

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