Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members  

jutil.cpp

00001 /********************************************************************************
00002  *   Jabberoo/Judo -- C++ Jabber Library                                        *
00003  *                                                                              * 
00004  *   Copyright (C) 1999-2000 Dave Smith (dave@jabber.org)                       *
00005  *                                                                              *
00006  *   This library is free software; you can redistribute it and/or              *
00007  *   modify it under the terms of the GNU Lesser General Public                 *
00008  *   License as published by the Free Software Foundation; either               *
00009  *   version 2.1 of the License, or (at your option) any later version.         *
00010  *                                                                              *
00011  *   This library is distributed in the hope that it will be useful,            *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of             *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU          *
00014  *   Lesser General Public License for more details.                            *
00015  *                                                                              *
00016  *   You should have received a copy of the GNU Lesser General Public           *
00017  *   License along with this library; if not, write to the Free Software        *
00018  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  *
00019  ********************************************************************************
00020  */
00021 
00022 #include "jutil.hh"
00023 using namespace jutil;
00024 
00025 #include <time.h>
00026 
00027 #ifdef WIN32
00028 #define snprintf _snprintf
00029 #define strcasecmp stricmp
00030 #include <string.h>
00031 #elif defined(MACOS)
00032 #include <ctype.h>
00033 #include <stdio.h>
00034 
00035 /* Compare lexigraphically two strings */
00036 
00037 int strcasecmp(const char *s1, const char *s2)
00038 {
00039     char c1, c2;
00040     while (1)
00041     {
00042         c1 = tolower(*s1++);
00043         c2 = tolower(*s2++);
00044         if (c1 < c2) return -1;
00045         if (c1 > c2) return 1;
00046         if (c1 == 0) return 0;
00047     }
00048 }
00049 #else
00050 #include <stdio.h>
00051 #endif
00052 
00053 bool CaseInsensitiveCmp::operator()(const std::string& lhs, const std::string& rhs) const
00054 {
00055      return (strcasecmp(lhs.c_str(), rhs.c_str()) < 0);
00056 }
00057 
00058 std::string jutil::getTimeStamp()
00059 {
00060     time_t t;
00061     struct tm *new_time;
00062     static char timestamp[18];
00063     int ret;
00064 
00065     t = time(NULL);
00066 
00067     if(t == (time_t)-1)
00068         return NULL;
00069     new_time = gmtime(&t);
00070 
00071     ret = snprintf(timestamp, 18, "%d%02d%02dT%02d:%02d:%02d", 1900+new_time->tm_year,
00072                    new_time->tm_mon+1, new_time->tm_mday, new_time->tm_hour,
00073                    new_time->tm_min, new_time->tm_sec);
00074 
00075     if(ret == -1)
00076         return "";
00077 
00078     return std::string(timestamp);
00079 }

Generated on Thu Jul 24 13:31:51 2003 for jabberoo by doxygen1.3-rc3