Sorry about the early mail. The patch is attached with this mail.
 
Thanks
Dimuthu

---------- Forwarded message ----------
From: Dimuthu Chathuranga <[EMAIL PROTECTED]>
Date: Aug 26, 2006 4:00 AM
Subject: [axis2]axis2/util changes
To: Apache AXIS C Developers List <axis-c-dev@ws.apache.org>

 
Hi,
 This attachments contain some changes I did with axis2/ util during working on Codegen tool.

add.tar.gz contains..

1. new header and .c file for new class properties which is very similar to java.util.properties class in java with some limited functionality.(loadXML and storeXML are not implemented, but load from .properties file and store to .properties file are implemented)

2. test for axis2_properties and axis2_date_time

svn_dff patch contains..

1. adding following functions to the axis2_string.h

         + axis2_string_substring_starting_at

         + axis2_string_substring_ending_at

        + axis2_string_tolower

        + axis2_string_toupper

2. fixing the bug in axis2_date_time, so it doesn't retain it value for multiple instances.

 

Thanks

Dimuthu

Attachment: add.tar.bz
Description: application/gzip-compressed

Index: test/unit/util/util_test.c
===================================================================
--- test/unit/util/util_test.c  (revision 429628)
+++ test/unit/util/util_test.c  (working copy)
@@ -38,8 +38,11 @@
     SUITE_ADD_TEST(suite, Testaxis2_uri_parse_string);
     SUITE_ADD_TEST(suite, Testaxis2_uri_parse_relative);
     SUITE_ADD_TEST(suite, Testaxis2_uri_clone);
-    SUITE_ADD_TEST(suite, Testaxis2_uri_get_path);
+    SUITE_ADD_TEST(suite, Testaxis2_uri_get_path); 
     /* Samisa - need to remove this as we run make check before make install
     SUITE_ADD_TEST(suite, Testaxis2_dir_handler_list_dir); */
+    SUITE_ADD_TEST(suite, Test_properties); 
+    SUITE_ADD_TEST(suite, Test_date_time); 
+
     return suite;
 }
Index: test/unit/util/util_test.h
===================================================================
--- test/unit/util/util_test.h  (revision 429628)
+++ test/unit/util/util_test.h  (working copy)
@@ -29,6 +29,8 @@
 #include "util_url_test.h"
 #include "util_string_test.h"
 #include "util_uri_test.h"
+#include "util_properties_test.h"
+#include "util_date_time_test.h"
 
 CuSuite* axis2_utilGetSuite();
 
Index: test/unit/util/Makefile.am
===================================================================
--- test/unit/util/Makefile.am  (revision 429628)
+++ test/unit/util/Makefile.am  (working copy)
@@ -15,7 +15,9 @@
                             util_class_loader_test.c \
                             util_string_test.c \
                             util_url_test.c \
-                            util_uri_test.c
+                            util_uri_test.c \
+                            util_properties_test.c \
+                            util_date_time_test.c
 
 INCLUDES = -I$(top_builddir)/include \
             -I${CUTEST_HOME}/include \
Index: include/axis2_string.h
===================================================================
--- include/axis2_string.h      (revision 429628)
+++ include/axis2_string.h      (working copy)
@@ -141,7 +141,63 @@
            const axis2_env_t *env,
            const axis2_char_t *_s,
            const axis2_char_t *_trim);
+   
+   /**
+    * replace given axis2_character with a new one.
+    * @param str       string operation apply
+    * @param old_char  the old axis2_character which would be replaced
+    * @param new_char  new axis2_char_tacter
+    * @return      replaced string
+    */
+   AXIS2_EXTERN axis2_char_t* AXIS2_CALL
+   axis2_string_replace(
+           axis2_char_t *str,
+           axis2_char_t old_char,
+           axis2_char_t new_char);
 
+   /**
+    * gives a sub string starting with given index.
+    * @param str       string operation apply
+    * @param c     starting index
+    * @return      substring
+    */
+   AXIS2_EXTERN axis2_char_t* AXIS2_CALL
+   axis2_string_substring_starting_at(
+           axis2_char_t *str,
+           int s );
+   
+   /**
+    * gives a sub string ending with given index.
+    * @param str       string operation apply
+    * @param c     ending index
+    * @return      substring
+    */
+   AXIS2_EXTERN axis2_char_t* AXIS2_CALL
+   axis2_string_substring_ending_at(
+           axis2_char_t *str,
+           int e );
+   
+   /**
+    * set a string to lowercase.
+    * @param str   string
+    * @return string with lowercase
+    */
+   AXIS2_EXTERN axis2_char_t*
+   axis2_string_tolower(
+           axis2_char_t *str );
+    
+   /**
+    * set a string to uppercase.
+    * @param str   string
+    * @return string with uppercase
+    */
+   AXIS2_EXTERN axis2_char_t*
+   axis2_string_toupper(
+           axis2_char_t *str );
+   
+     
+   
+
 #define AXIS2_STRDUP(pts, env) \
         axis2_strdup(pts, env)
 
Index: include/axis2_date_time.h
===================================================================
--- include/axis2_date_time.h   (revision 429628)
+++ include/axis2_date_time.h   (working copy)
@@ -157,7 +157,7 @@
         ((date_time)->ops->free (date_time, env))
 
 #define AXIS2_DATE_TIME_DESERIALIZE_TIME(date_time, env, time ) \
-        ((date_time)->ops->deserialize_time (date_time, env, time_str))
+        ((date_time)->ops->deserialize_time (date_time, env, time))
 
 #define AXIS2_DATE_TIME_DESERIALIZE_DATE(date_time, env, date) \
         ((date_time)->ops->deserialize_date (date_time, env, date_str))
Index: src/string.c
===================================================================
--- src/string.c        (revision 429628)
+++ src/string.c        (working copy)
@@ -369,3 +369,75 @@
     return _q;
 }
 
+AXIS2_EXTERN axis2_char_t* AXIS2_CALL
+axis2_string_replace( axis2_char_t* str, axis2_char_t old, axis2_char_t new )
+{
+    axis2_char_t* str_returns = str;
+    for (  ; *str != '\0' ; str ++ )
+    {
+        if ( *str == old )
+        {
+            *str = new;
+        }
+    }
+    return str_returns;
+}
+
+AXIS2_EXTERN axis2_char_t* AXIS2_CALL
+axis2_string_substring_starting_at( axis2_char_t* str, int s )
+{
+    int len;
+    int pos_to_shift;
+
+    len = strlen ( str );
+    pos_to_shift = len - s +1;
+
+    if ( len <= s )
+    {
+        return NULL;
+    }
+    memmove (str , str + s, pos_to_shift );
+    return str;
+}
+
+
+AXIS2_EXTERN axis2_char_t* AXIS2_CALL
+axis2_string_substring_ending_at( axis2_char_t* str, int e )
+{
+    axis2_char_t* ptr = NULL;
+    int length = 0;
+
+    length = strlen( str );
+    ptr = str;
+    if( length <=  e )
+    {
+        return NULL;
+    }
+    ptr += e;
+    *ptr = '\0';
+    return str;
+}
+
+
+AXIS2_EXTERN axis2_char_t* AXIS2_CALL
+axis2_string_tolower( axis2_char_t* str )
+{
+    axis2_char_t* temp_str = NULL;
+    for ( temp_str = str; *temp_str != '\0' ; temp_str ++ )
+    {
+       *temp_str= tolower(*temp_str );
+    }
+    return str;
+}
+
+AXIS2_EXTERN axis2_char_t* AXIS2_CALL
+axis2_string_toupper( axis2_char_t* str )
+{
+    axis2_char_t* temp_str = NULL;
+    for ( temp_str = str; *temp_str != '\0' ; temp_str ++ )
+    {
+       *temp_str= toupper(*temp_str );
+    }
+    return str;
+}
+
Index: src/date_time.c
===================================================================
--- src/date_time.c     (revision 429628)
+++ src/date_time.c     (working copy)
@@ -28,7 +28,12 @@
 {
     axis2_date_time_t date_time;
     
-    struct tm* utcTime;
+    int year;
+    int mon;
+    int day;
+    int hour;
+    int min;
+    int sec;
 
 } axis2_date_time_impl_t;
 
@@ -81,6 +86,7 @@
 {
     axis2_date_time_impl_t *date_time_impl = NULL;
     time_t now;
+    struct tm* utc_time = NULL;
    
     AXIS2_ENV_CHECK(env, NULL);
 
@@ -94,7 +100,13 @@
     }
     
     now = time (NULL );
-    date_time_impl-> utcTime = gmtime ( &now);
+    utc_time = gmtime ( &now);
+    date_time_impl-> year= utc_time-> tm_year;
+    date_time_impl-> mon= utc_time-> tm_mon;
+    date_time_impl-> day= utc_time-> tm_mday;
+    date_time_impl-> hour= utc_time-> tm_hour;
+    date_time_impl-> min= utc_time-> tm_min;
+    date_time_impl-> sec= utc_time-> tm_sec;
 
     date_time_impl->date_time.ops = 
         AXIS2_MALLOC (env->allocator, sizeof(axis2_date_time_ops_t));
@@ -135,12 +147,6 @@
         AXIS2_FREE(env->allocator, date_time->ops);
         date_time->ops = NULL;
     }
-
-    if(date_time_impl->utcTime)
-    {
-        free ( date_time_impl->utcTime);
-        date_time_impl->utcTime = NULL;
-    }
     
     if(date_time_impl)
     {
@@ -157,15 +163,13 @@
                         const char* time_str)
 {
     axis2_date_time_impl_t *date_time_impl = NULL;
-    struct tm* time = NULL;
     
     AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
     
     date_time_impl = AXIS2_INTF_TO_IMPL(date_time);
-    time = date_time_impl->utcTime;
 
-    sscanf (time_str, "%d:%d:%dZ" , &time-> tm_hour, &time-> tm_min,
-            &time-> tm_sec );
+    sscanf (time_str, "%d:%d:%dZ" , &date_time_impl-> hour, &date_time_impl-> 
min,
+            &date_time_impl-> sec );
     return AXIS2_SUCCESS;
 }
 
@@ -175,16 +179,14 @@
                         const char* date_str)
 {
     axis2_date_time_impl_t *date_time_impl = NULL;
-    struct tm* time = NULL;
     
     AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
     
     date_time_impl = AXIS2_INTF_TO_IMPL(date_time);
-    time = date_time_impl->utcTime;
 
-    sscanf (date_str, "%d-%d-%d" , &time-> tm_year, &time -> tm_mon,
-            &time-> tm_mday );
-    time-> tm_year -= 1900;
+    sscanf (date_str, "%d-%d-%d" , &date_time_impl-> year, &date_time_impl-> 
mon,
+            &date_time_impl-> day );
+    date_time_impl-> year -= 1900;
     return AXIS2_SUCCESS;
 }
     
@@ -194,17 +196,15 @@
                         const char* date_time_str)
 {
     axis2_date_time_impl_t *date_time_impl = NULL;
-    struct tm* time = NULL;
     
     AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
     
     date_time_impl = AXIS2_INTF_TO_IMPL(date_time);
-    time = date_time_impl->utcTime;
 
-    sscanf (date_time_str, "%d-%d-%dT%d:%d:%dZ", &time-> tm_year, &time -> 
tm_mon,
-            &time-> tm_mday, &time-> tm_hour, &time-> tm_min,
-            &time-> tm_sec );
-    time-> tm_year -= 1900;
+    sscanf (date_time_str, "%d-%d-%dT%d:%d:%dZ", &date_time_impl-> year, 
&date_time_impl-> mon,
+            &date_time_impl-> day, &date_time_impl-> hour, &date_time_impl-> 
min,
+            &date_time_impl-> sec );
+    date_time_impl-> year -= 1900;
     return AXIS2_SUCCESS;
 }
     
@@ -215,19 +215,17 @@
                         int hour, int min, int second )
 {
     axis2_date_time_impl_t *date_time_impl = NULL;
-    struct tm* time = NULL;
     
     AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
     
     date_time_impl = AXIS2_INTF_TO_IMPL(date_time);
-    time = date_time_impl->utcTime;
 
-    if ( year > -1 )time-> tm_year = year - 1900;
-    if ( month > -1 )time-> tm_mon = month;
-    if ( day > -1 )time-> tm_mday = day;
-    if ( hour > -1 )time -> tm_hour = hour;
-    if ( min > -1 )time -> tm_min = min;
-    if ( second > -1 )time -> tm_sec = second;
+    if ( year > -1 )date_time_impl-> year = year - 1900;
+    if ( month > -1 )date_time_impl-> mon = month;
+    if ( day > -1 )date_time_impl-> day = day;
+    if ( hour > -1 )date_time_impl-> hour = hour;
+    if ( min > -1 )date_time_impl-> min = min;
+    if ( second > -1 )date_time_impl-> sec = second;
     return AXIS2_SUCCESS;
 }
  
@@ -236,37 +234,34 @@
                         const axis2_env_t *env )
 {
     axis2_date_time_impl_t *date_time_impl = NULL;
-    struct tm* time = NULL;
     char* time_str = NULL;
     
     AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
     
     date_time_impl = AXIS2_INTF_TO_IMPL(date_time);
-    time = date_time_impl->utcTime;
 
-    time_str = malloc ( sizeof (char) * 32 );
+    time_str = (char*)AXIS2_MALLOC( env->allocator, sizeof (char) * 32 );
         
-    sprintf (time_str, "%d:%d:%dZ" , time-> tm_hour, time-> tm_min, time-> 
tm_sec );
+    sprintf (time_str, "%d:%d:%dZ" , date_time_impl-> hour, date_time_impl-> 
min, date_time_impl-> sec );
     return time_str;
 }
+
 char* AXIS2_CALL
 axis2_date_time_serialize_date (axis2_date_time_t *date_time,
                         const axis2_env_t *env )
 {
     axis2_date_time_impl_t *date_time_impl = NULL;
-    struct tm* time= NULL;
     char* date_str = NULL;
     
     AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
     
     date_time_impl = AXIS2_INTF_TO_IMPL(date_time);
-    time = date_time_impl->utcTime;
 
-    date_str = malloc ( sizeof (char) * 32 );
+    date_str = (char*)AXIS2_MALLOC( env-> allocator, sizeof (char) * 32 );
         
-    sprintf (date_str, "%d-%d-%d" , time-> tm_year + 1900,
-            time -> tm_mon,
-            time-> tm_mday );
+    sprintf (date_str, "%d-%d-%d" , date_time_impl-> year + 1900,
+            date_time_impl-> mon,
+            date_time_impl-> day );
     return date_str;  
 }
 char* AXIS2_CALL
@@ -274,19 +269,17 @@
                         const axis2_env_t *env )
 {
     axis2_date_time_impl_t *date_time_impl = NULL;
-    struct tm* time = NULL;
     char* date_time_str = NULL;
     
     AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
     
     date_time_impl = AXIS2_INTF_TO_IMPL(date_time);
-    time = date_time_impl->utcTime;
 
-    date_time_str = malloc ( sizeof (char) * 32 );
+    date_time_str = AXIS2_MALLOC( env-> allocator, sizeof (char) * 32 );
         
-    sprintf (date_time_str, "%d-%d-%dT%d:%d:%dZ" , time-> tm_year+1900,
-            time -> tm_mon, time-> tm_mday, time-> tm_hour, time-> tm_min,
-            time-> tm_sec );
+    sprintf (date_time_str, "%d-%d-%dT%d:%d:%dZ" , date_time_impl-> year+1900,
+            date_time_impl-> mon, date_time_impl-> day, date_time_impl-> hour, 
date_time_impl-> min,
+            date_time_impl-> sec );
     return date_time_str;
 }
 
Index: src/Makefile.am
===================================================================
--- src/Makefile.am     (revision 429628)
+++ src/Makefile.am     (working copy)
@@ -32,7 +32,8 @@
                         base64.c \
                         uri.c \
                         date_time.c \
-                        base64_binary.c
+                        base64_binary.c \
+                        properties.c 
                         
 libaxis2_util_la_LIBADD =  \
                     $(top_builddir)/src/platforms/unix/libaxis2_unix.la \
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to