1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include <precomp.h>
25 
26 #include <ctype.h>
27 #include <cosv/comfunc.hxx>
28 #include <cosv/string.hxx>
29 #include <cosv/x.hxx>
30 #include <cosv/std_outp.hxx>
31 
32 
33 
34 namespace csv
35 {
36 
37 
38 void
GetInfo(ostream & o_rOutputMedium) const39 X_Default::GetInfo( ostream & o_rOutputMedium ) const
40 {
41     o_rOutputMedium << "Error (general exception): ";
42     o_rOutputMedium << sMessage
43                     << Endl;
44 }
45 
46 intt
count_chars(const char * str,char c)47 count_chars(const char * str, char c)
48 {
49 	intt nCount = 0;
50 	for ( const char * pSpc = strchr(str, c);
51 		  pSpc != 0;
52 		  pSpc = strchr(pSpc+1, c) )
53 	{
54 		nCount++;
55 	}
56 	return nCount;
57 }
58 
59 
60 
61 // Zeit-Typecasts
62 bool
str2date(const char * str,int & out_day,int & out_month,int & out_year)63 str2date(const char * str, int & out_day, int & out_month, int & out_year)
64 {
65    const char * z = str;
66    out_day = 0;
67    out_month = 0;
68    out_year = 0;
69 
70    while (isdigit(*z))
71 	  out_day = 10*out_day + *(z++) - '0';
72    if (*z == 0)
73 	  return false;
74    z++;
75    while (isdigit(*z))
76 	  out_month = 10*out_month + *(z++) - '0';
77    if (*z == 0)
78 	  return false;
79    z++;
80    while (isdigit(*z))
81 	  out_year = 10*out_year + *(z++) - '0';
82    return true;
83 }
84 
85 void
date2str(String & out_Str,int day,int month,int year)86 date2str(String & out_Str, int day, int month, int year)
87 {
88    char buf[11] = "00.00.0000";
89    buf[0] = static_cast<char>(day/10 + '0');
90    buf[1] = static_cast<char>(day%10 + '0');
91    buf[3] = static_cast<char>(month/10 + '0');
92    buf[4] = static_cast<char>(month%10 + '0');
93 
94    if (year < 100)
95    {
96 	  buf[6] = static_cast<char>(year/10 + '0');
97 	  buf[7] = static_cast<char>(year%10 + '0');
98 	  buf[8] = 0;
99    }
100    else
101    {
102 	  buf[6] = static_cast<char>(year/1000 + '0');
103 	  buf[7] = static_cast<char>(year%1000/100 + '0');
104 	  buf[8] = static_cast<char>(year%100/10 + '0');
105 	  buf[9] = static_cast<char>(year%10 + '0');
106    }
107    out_Str = buf;
108 }
109 
110 bool
str2time(const char * str,int & out_hour,int & out_min,int & out_sec)111 str2time(const char * str, int & out_hour, int & out_min, int & out_sec)
112 {
113    const char * z = str;
114    out_hour = 0;
115    out_min = 0;
116    out_sec = 0;
117 
118    while (isdigit(*z))
119 	  out_hour = 10*out_hour + *(z++) - '0';
120    if (*z == 0)
121 	  return false;
122    z++;
123    while (isdigit(*z))
124 	  out_min = 10*out_min + *(z++) - '0';
125    if (*z == 0)
126 	  return false;
127    z++;
128    while (isdigit(*z))
129 	  out_sec = 10*out_sec + *(z++) - '0';
130    return true;
131 }
132 
133 void
time2str(String & out_Str,int hour,int min,int sec)134 time2str(String & out_Str, int hour, int min, int sec)
135 {
136    char buf[9] = "00:00:00";
137    buf[0] = static_cast<char>(hour/10 + '0');
138    buf[1] = static_cast<char>(hour%10 + '0');
139    buf[3] = static_cast<char>(min/10 + '0');
140    buf[4] = static_cast<char>(min%10 + '0');
141    buf[6] = static_cast<char>(sec/10 + '0');
142    buf[7] = static_cast<char>(sec%10 + '0');
143    out_Str = buf;
144 }
145 
146 
147 
148 }   // namespace csv
149 
150 
151 
152