root/trunk/txlib/txunico.c

Revision 1, 4.6 kB (checked in by jvw, 3 years ago)

Initial check-in for TxWin? version 1.02 sources

Line 
1//
2//                     TxWin, Textmode Windowing Library
3//
4//   Original code Copyright (c) 1995-2005 Fsys Software and Jan van Wijk
5//
6// ==========================================================================
7//
8// This file contains Original Code and/or Modifications of Original Code as
9// defined in and that are subject to the GNU Lesser General Public License.
10// You may not use this file except in compliance with the License.
11// BY USING THIS FILE YOU AGREE TO ALL TERMS AND CONDITIONS OF THE LICENSE.
12// A copy of the License is provided with the Original Code and Modifications,
13// and is also available at http://www.dfsee.com/txwin/lgpl.htm
14//
15// This library is free software; you can redistribute it and/or modify
16// it under the terms of the GNU Lesser General Public License as published
17// by the Free Software Foundation; either version 2.1 of the License,
18// or (at your option) any later version.
19//
20// This library is distributed in the hope that it will be useful,
21// but WITHOUT ANY WARRANTY; without even the implied warranty of
22// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23// See the GNU Lesser General Public License for more details.
24//
25// You should have received a copy of the GNU Lesser General Public License
26// along with this library; (lgpl.htm) if not, write to the Free Software
27// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28//
29// Questions on TxWin licensing can be directed to: txwin@fsys.nl
30//
31// ==========================================================================
32//
33// TxLib Unicode string handling
34//
35
36#include <txlib.h>                              // TxLib interface
37
38/*****************************************************************************/
39// Append translated Unicode string-fragment to an ASCII string
40/*****************************************************************************/
41char *TxUnicAppend                              // RET   ptr to ASCII string
42(
43   USHORT             *uni,                     // IN    Unicode string part
44   char               *asc,                     // INOUT ASCII string
45   USHORT              len                      // IN    maximum Unicode length
46)
47{
48   char               *pos = asc + strlen( asc); // append position
49   USHORT              i;
50
51   for (i = 0; i < len && uni[i] != 0; i++)     // until len or zero-unicode
52   {
53      if (uni[i] > 0xff)
54      {
55         if (uni[i] != 0xffff)
56         {
57            *pos++ = '*';                       // to be refined
58         }
59      }
60      else
61      {
62         *pos++ = (char) (uni[i] & 0xff);
63      }
64   }
65   *pos = '\0';                                 // terminate the string
66   return (asc);
67}                                               /* end TxUnicAppend          */
68/*---------------------------------------------------------------------------*/
69
70
71/*****************************************************************************/
72// Perform a Unicode to ASCII case-sensitive stringcompare (aka strncmp)
73/*****************************************************************************/
74int TxUnicStrncmp                               // RET   compare result
75(
76   char               *uni,                     // IN    Unicode string
77   char               *asc,                     // IN    ASCII   string
78   size_t              len                      // IN    max ASCII comp-length
79)
80{
81   size_t              i;
82   int                 rc = 0;
83
84   for ( i = 0; (rc == 0) && (i < len) && *asc; i++, asc++, uni += 2)
85   {
86      rc = *uni - *asc;
87   }
88   return (rc);
89}                                               /* end TxUnicStrncmp         */
90/*---------------------------------------------------------------------------*/
91
92
93/*****************************************************************************/
94// Perform a Unicode to ASCII case-insensitive stringcompare (aka strnicmp)
95/*****************************************************************************/
96int TxUnicStrnicmp                              // RET   compare result
97(
98   char               *uni,                     // IN    Unicode string
99   char               *asc,                     // IN    ASCII   string
100   size_t              len                      // IN    max ASCII comp-length
101)
102{
103   size_t              i;
104   int                 rc = 0;
105
106   for ( i = 0; (rc == 0) && (i < len) && *asc; i++, asc++, uni += 2)
107   {
108      rc = ((*uni) & 0xdf) - ((*asc) & 0xdf);
109   }
110   return (rc);
111}                                               /* end TxUnicStrnicmp        */
112/*---------------------------------------------------------------------------*/
Note: See TracBrowser for help on using the browser.