merged tag ooo/OOO330_m14
[LibreOffice.git] / cosv / source / service / comfunc.cxx
blobab8f274d90d8b376fdb2c69c7cb195ce00b4c3ef
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 #include <precomp.h>
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>
38 namespace csv
42 void
43 X_Default::GetInfo( ostream & o_rOutputMedium ) const
45 o_rOutputMedium << "Error (general exception): ";
46 o_rOutputMedium << sMessage
47 << Endl;
50 intt
51 count_chars(const char * str, char c)
53 intt nCount = 0;
54 for ( const char * pSpc = strchr(str, c);
55 pSpc != 0;
56 pSpc = strchr(pSpc+1, c) )
58 nCount++;
60 return nCount;
65 // Zeit-Typecasts
66 bool
67 str2date(const char * str, int & out_day, int & out_month, int & out_year)
69 const char * z = str;
70 out_day = 0;
71 out_month = 0;
72 out_year = 0;
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;
89 void
90 date2str(String & out_Str, int day, int month, int year)
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');
98 if (year < 100)
100 buf[6] = static_cast<char>(year/10 + '0');
101 buf[7] = static_cast<char>(year%10 + '0');
102 buf[8] = 0;
104 else
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');
111 out_Str = buf;
114 bool
115 str2time(const char * str, int & out_hour, int & out_min, int & out_sec)
117 const char * z = str;
118 out_hour = 0;
119 out_min = 0;
120 out_sec = 0;
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;
137 void
138 time2str(String & out_Str, int hour, int min, int sec)
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;
152 } // namespace csv