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