File: WeString.c

package info (click to toggle)
xwpe 1.5.30a-2.1
  • links: PTS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, squeeze, stretch, wheezy
  • size: 1,652 kB
  • ctags: 1,879
  • sloc: ansic: 26,571; makefile: 121; sh: 70
file content (144 lines) | stat: -rw-r--r-- 2,756 bytes parent folder | download | duplicates (7)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*-------------------------------------------------------------------------*\
  <WeString.c> -- Some string routines for xwpe

  Date      Programmer  Description
  04/27/97  Dennis      Created based on functions from "we_hfkt.c".
\*-------------------------------------------------------------------------*/

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *\
  Original header of "we_hfkt.c"
\* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* we_hfkt.c                                              */
/* Copyright (C) 1993 Fred Kruse                          */
/* This is free software; you can redistribute it and/or  */
/* modify it under the terms of the                       */
/* GNU General Public License, see the file COPYING.      */

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *\
  Includes
\* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
#include "Xwpe.h"
#include "WeString.h"
#include <string.h>
#include <stdlib.h>
#include <ctype.h>


int WpeStrnccmp(const char *s1, const char *s2, int n)
{
 /* Added a check for end of string. */
 for (; (n > 0) && (*s1) && (toupper(*s1) == toupper(*s2));
      n--, s1++, s2++) ;
 return(n > 0 ? toupper(*s1) - toupper(*s2) : 0);
}

int WpeStrccmp(const char *s1, const char *s2)
{
 for (; (*s1) && (toupper(*s1) == toupper(*s2)); s1++, s2++) ;
 return(toupper(*s1) - toupper(*s2));
}

char *WpeStrcstr(char *str, const char *substr)
{
 const int len = strlen(substr);

 for (; *str; str++)
 {
  if (WpeStrnccmp(str, substr, len) == 0)
  {
   return(str);
  }
 }
 return(NULL);
}

char *WpeStrdup(const char *str)
{
 char *newstr;
 
 newstr = WpeMalloc((strlen(str)+1)*sizeof(char));
 if (newstr != NULL)
 {
  strcpy(newstr, str);
 }
 return(newstr);
}

int WpeNumberOfPlaces(int n)
{
 int i;

 if (n == 0)
 {
  return(1);
 }
 else if (n < 0)
 {
  n = -n;
 }
 for (i = 0; n > 0; n /= 10, i++) ;
 return(i);
}

char *WpeNumberToString(int n, int len, char *s)
{
 int nlen;

 nlen = WpeNumberOfPlaces(n);
 if (nlen > len)
 {
  nlen = len;
 }
 else
 {
  memset(s, ' ', len - nlen);
 }
 s[len] = '\0';
 for (; nlen > 0 ; n /= 10, nlen--)
 {
  len--;
  s[len] = (n % 10) + '0';
 }
 return(s);
}

int WpeStringToNumber(const char *s)
{
 /* This checking of blanks is probably not needed. */
 while ((*s) == ' ')
 {
  s++;
 }
 return(atoi(s));
}

char *WpeStringToUpper(char *s)
{
 char *s2;

 for (s2 = s; *s2; s2++)
 {
  *s2 = toupper(*s2);
 }
 return (s);
}

char *WpeStringBlank(char *s, int len)
{
 memset(s, ' ', len);
 s[len] = '\0';
 return(s);
}

char *WpeStringCutChar(char *s, char c)
{
 char *tmp;

 tmp = strrchr(s, c);
 if (tmp != NULL)
 {
  *tmp = '\0';
 }
 return(s);
}