source: PSPA/madxPSPA/src/mad_str.h

Last change on this file was 430, checked in by touze, 11 years ago

import madx-5.01.00

File size: 3.3 KB
Line 
1#ifndef MAD_STR_H
2#define MAD_STR_H
3
4// types
5
6struct int_array;
7struct char_array;
8struct char_p_array;
9
10// interface
11
12void  mycpy(char* sout, const char* sin);
13char* mystrchr(char* string, char c);
14void  mystrcpy(struct char_array* target, char* source);
15char* mystrstr(char* string, char* s);
16void  myrepl(char* in, char* out, char* string_in, char* string_out);
17int   mysplit(char* buf, struct char_p_array* list);
18
19void  conv_char(const char* string, struct int_array* tint);
20void  stolower_nq(char* s);
21char* strip(char* name);
22int   supp_lt(char* inbuf, int flag);
23void  supp_mul_char(char c, char* string);
24char* supp_tb(char* string);      /* suppress trailing blanks in string */
25int   zero_string(char* string);  /* returns 1 if string defaults to '0', else 0 */
26char* buffer(char* string);       /* obsolete, replaced by permbuff */
27char* permbuff(char* string);     /* copy string to permanent buffer */
28char* tmpbuff(const char* string);      /* copy string to temporary allocated buffer */
29// int   compare_no_case(char* string_1, char* string_2); // replaced by string_icmp
30int   is_token(char* pb, char* string, int slen);
31char* join(char** it_list, int n);
32char* join_b(char** it_list, int n);
33char  next_non_blank(char* string);
34int   next_non_blank_pos(char* string);
35char* noquote(char* string);
36int   quote_level(char* string, char* send);
37int   square_to_colon(char* string);
38
39// inline functions
40
41#include <ctype.h>
42
43static inline int
44str_pos(const char s[], char c)
45{
46  int i;
47  for (i = 0; s[i]; i++)
48    if (s[i] == c) return i;
49  return -1;
50}
51
52static inline int
53char_cnt(char c, const char* s)
54  /* returns number of occurrences of character c in string */
55{
56  int i, k = 0;
57  for (i = 0; s[i]; i++)
58    if(s[i] == c) k++;
59  return k;
60}
61
62static inline int
63next_char(char c, char** toks, int start, int nitem)
64  /* returns the number of the token starting with c after token start */
65{
66  int i;
67  for (i = start; i < nitem; i++)
68    if(*toks[i] == c) return i;
69  return -1;
70}
71
72static inline void
73replace(char* buf, char in, char out)
74  /* replaces character in by character out in string buf */
75{
76  int j;
77  for (j = 0; buf[j]; j++)
78    if (buf[j] == in) buf[j] = out;
79}
80
81static inline char*
82stolower(char* s)  /* converts string to lower in place */
83{
84  int j;
85  for (j = 0; s[j]; j++) {
86    unsigned char c = s[j];
87    s[j] = tolower(c);
88  }
89  return s;
90}
91
92static inline char*
93stoupper(char* s)  /* converts string to upper in place */
94{
95  int j;
96  for (j = 0; s[j]; j++) {
97    unsigned char c = s[j];
98    s[j] = toupper(c);
99  }
100  return s;
101}
102
103static inline int
104string_icmp(const char* s1, const char *s2)  /* case insitive string compare */
105{
106  int j;
107  for (j = 0; s1[j] && s2[j]; j++) {
108    unsigned char c1 = s1[j], c2 = s2[j];
109    int ic1 = tolower(c1), ic2 = tolower(c2);
110    if (ic1 != ic2) return ic2-ic1;
111  }
112  return s2[j]-s1[j];
113}
114
115static inline int
116string_cnt(char c, int n, char* toks[])
117  /* returns number of strings in toks starting with character c */
118{
119  int i, k = 0;
120  for (i = 0; i < n; i++)
121    if(*toks[i] == c) k++;
122  return k;
123}
124
125static inline void
126supp_char(char c, char* s)
127  /* suppresses character c in string */
128{
129  char *p;
130  for (p = s; *s; s++)
131    if (*s != c) *p++ = *s;
132  *p = '\0';
133}
134
135static inline int
136all_blank(char* s)
137{
138  int i;
139  for (i = 0; s[i]; i++)
140    if(s[i] != ' ') return 0;
141  return 1;
142}
143
144#endif // MAD_STR_H
145
Note: See TracBrowser for help on using the repository browser.