xref: /AOO41X/main/cosv/source/service/comfunc.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include <precomp.h>
29 
30 #include <ctype.h>
31 #include <cosv/comfunc.hxx>
32 #include <cosv/string.hxx>
33 #include <cosv/x.hxx>
34 #include <cosv/std_outp.hxx>
35 
36 
37 
38 namespace csv
39 {
40 
41 
42 void
43 X_Default::GetInfo( ostream & o_rOutputMedium ) const
44 {
45     o_rOutputMedium << "Error (general exception): ";
46     o_rOutputMedium << sMessage
47                     << Endl;
48 }
49 
50 intt
51 count_chars(const char * str, char c)
52 {
53 	intt nCount = 0;
54 	for ( const char * pSpc = strchr(str, c);
55 		  pSpc != 0;
56 		  pSpc = strchr(pSpc+1, c) )
57 	{
58 		nCount++;
59 	}
60 	return nCount;
61 }
62 
63 
64 
65 // Zeit-Typecasts
66 bool
67 str2date(const char * str, int & out_day, int & out_month, int & out_year)
68 {
69    const char * z = str;
70    out_day = 0;
71    out_month = 0;
72    out_year = 0;
73 
74    while (isdigit(*z))
75 	  out_day = 10*out_day + *(z++) - '0';
76    if (*z == 0)
77 	  return false;
78    z++;
79    while (isdigit(*z))
80 	  out_month = 10*out_month + *(z++) - '0';
81    if (*z == 0)
82 	  return false;
83    z++;
84    while (isdigit(*z))
85 	  out_year = 10*out_year + *(z++) - '0';
86    return true;
87 }
88 
89 void
90 date2str(String & out_Str, int day, int month, int year)
91 {
92    char buf[11] = "00.00.0000";
93    buf[0] = static_cast<char>(day/10 + '0');
94    buf[1] = static_cast<char>(day%10 + '0');
95    buf[3] = static_cast<char>(month/10 + '0');
96    buf[4] = static_cast<char>(month%10 + '0');
97 
98    if (year < 100)
99    {
100 	  buf[6] = static_cast<char>(year/10 + '0');
101 	  buf[7] = static_cast<char>(year%10 + '0');
102 	  buf[8] = 0;
103    }
104    else
105    {
106 	  buf[6] = static_cast<char>(year/1000 + '0');
107 	  buf[7] = static_cast<char>(year%1000/100 + '0');
108 	  buf[8] = static_cast<char>(year%100/10 + '0');
109 	  buf[9] = static_cast<char>(year%10 + '0');
110    }
111    out_Str = buf;
112 }
113 
114 bool
115 str2time(const char * str, int & out_hour, int & out_min, int & out_sec)
116 {
117    const char * z = str;
118    out_hour = 0;
119    out_min = 0;
120    out_sec = 0;
121 
122    while (isdigit(*z))
123 	  out_hour = 10*out_hour + *(z++) - '0';
124    if (*z == 0)
125 	  return false;
126    z++;
127    while (isdigit(*z))
128 	  out_min = 10*out_min + *(z++) - '0';
129    if (*z == 0)
130 	  return false;
131    z++;
132    while (isdigit(*z))
133 	  out_sec = 10*out_sec + *(z++) - '0';
134    return true;
135 }
136 
137 void
138 time2str(String & out_Str, int hour, int min, int sec)
139 {
140    char buf[9] = "00:00:00";
141    buf[0] = static_cast<char>(hour/10 + '0');
142    buf[1] = static_cast<char>(hour%10 + '0');
143    buf[3] = static_cast<char>(min/10 + '0');
144    buf[4] = static_cast<char>(min%10 + '0');
145    buf[6] = static_cast<char>(sec/10 + '0');
146    buf[7] = static_cast<char>(sec%10 + '0');
147    out_Str = buf;
148 }
149 
150 
151 
152 }   // namespace csv
153 
154 
155 
156