blob: f37beacb6a97eb8c627e6a73f282254c96c7228b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
/*************************************************************************
*
* DBCS.C
*
* DBCS routines, ported from DOS
*
* Copyright (c) 1995 Microsoft Corporation
*
* $Log: N:\NT\PRIVATE\NW4\NWSCRIPT\VCS\DBCS.C $
*
* Rev 1.1 22 Dec 1995 14:24:10 terryt
* Add Microsoft headers
*
* Rev 1.0 15 Nov 1995 18:06:44 terryt
* Initial revision.
*
* Rev 1.1 25 Aug 1995 16:22:26 terryt
* Capture support
*
* Rev 1.0 15 May 1995 19:10:24 terryt
* Initial revision.
*
*************************************************************************/
/*
** dbcs.c - DBCS functions for DOS apps.
**
** Written by RokaH and DavidDi.
*/
/* Headers
**********/
// IsDBCSLeadByte taken out of NT because there is one built in.
// I left the Next and Prev in because I don't know whether this
// algorithm is "safer" than the built in code.
#include "common.h"
/*
** unsigned char *NWAnsiNext(unsigned char *puch);
**
** Moves to the next character in a string.
**
** Arguments: puch - pointer to current location in string
**
** Returns: char * - Pointer to next character in string.
**
** Globals: none
**
** N.b., if puch points to a null character, NWAnsiNext() will return puch.
*/
unsigned char *NWAnsiNext(unsigned char *puch)
{
if (*puch == '\0')
return(puch);
else if (IsDBCSLeadByte(*puch))
puch++;
puch++;
return(puch);
}
/*
** unsigned char *NWAnsiPrev(unsigned char *psz, unsigned char *puch);
**
** Moves back one character in a string.
**
** Arguments: psz - pointer to start of string
** puch - pointer to current location in string
**
** Returns: char * - Pointer to previous character in string.
**
** Globals: none
**
** N.b., if puch <= psz, NWAnsiPrev() will return psz.
**
** This function is implemented in a very slow fashion because we do not wish
** to trust that the given string is necessarily DBCS "safe," i.e., contains
** only single-byte characters and valid DBCS characters. So we start from
** the beginning of the string and work our way forward.
*/
unsigned char *NWAnsiPrev(unsigned char *psz, unsigned char *puch)
{
unsigned char *puchPrevious;
do
{
puchPrevious = psz;
psz = NWAnsiNext(psz);
} while (*psz != '\0' && psz < puch);
return(puchPrevious);
}
|