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