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