FrontISTR  5.9.0
Large-scale structural analysis program with finit element method
hecd_util.cpp
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright (c) 2019 FrontISTR Commons
3  * This software is released under the MIT License, see LICENSE.txt
4  *****************************************************************************/
5 /*
6  hecd_util ver.1.0
7 */
8 
9 #include "hecd_util.h"
10 
11 namespace hecd_util {
12 
13 void cleanup_token(char *s) {
14  char buff[256];
15  size_t s_size = strlen(s) + 1;
16  cleanup_token(s, buff);
17  snprintf(s, s_size, "%s", buff);
18 }
19 
20 void cleanup_token(char *src, char *dest) {
21 #define is_skip_char(x) \
22  (x == ' ' || x == '=' || x == '\t' || x == '\r' || x == '\n')
23  char *s = src;
24 
25  while (*s && is_skip_char(*s)) s++;
26 
27  char *d = dest;
28 
29  while (*s && !is_skip_char(*s)) {
30  *d = *s;
31  d++;
32  s++;
33  }
34 
35  *d = 0;
36 }
37 
38 void toupper(char *s) {
39  while (*s) {
40  *s = (char)::toupper(*s);
41  s++;
42  }
43 }
44 
45 void toupper(const char *src, char *dest) {
46  char *s = (char *)src;
47 
48  while (*s) {
49  *dest = (char)::toupper(*s);
50  s++;
51  dest++;
52  }
53 
54  *dest = 0;
55 }
56 
57 void tolower(char *s) {
58  while (*s) {
59  *s = (char)::tolower(*s);
60  s++;
61  }
62 }
63 
64 void tolower(const char *src, char *dest) {
65  char *s = (char *)src;
66 
67  while (*s) {
68  *dest = (char)::tolower(*s);
69  s++;
70  dest++;
71  }
72 
73  *dest = 0;
74 }
75 
76 void remove_cr(char *s) {
77  while (*s) {
78  if (*s == '\r' || *s == '\n') {
79  *s = 0;
80  return;
81  }
82 
83  s++;
84  }
85 }
86 
87 // note)
88 // I/O of HEC-MW does not support '1e+2' formatted number.
89 // Then ftos converts '1e+2' to '1.0e+2'
90 
91 void ftos(double x, char *s) {
92  char buff[256];
93  snprintf(buff, sizeof(buff), "%.10lg", x);
94  char *p = buff;
95  bool fg_dot = false;
96 
97  while (*p) {
98  if (*p == '.') {
99  fg_dot = true;
100 
101  } else if (*p == 'e' || *p == 'E') {
102  if (!fg_dot) {
103  *s = '.';
104  s++;
105  *s = '0';
106  s++;
107  }
108  }
109 
110  *s = *p;
111  p++;
112  s++;
113  }
114 
115  *s = 0;
116 }
117 
118 } // end of namespace hecd_util
#define is_skip_char(x)
void tolower(char *s)
Definition: hecd_util.cpp:57
void toupper(char *s)
Definition: hecd_util.cpp:38
void cleanup_token(char *s)
Definition: hecd_util.cpp:13
void remove_cr(char *s)
Definition: hecd_util.cpp:76
void ftos(double x, char *s)
Definition: hecd_util.cpp:91