Changeset 180


Ignore:
Timestamp:
Jan 7, 2007, 5:27:39 PM (19 years ago)
Author:
cinc
Message:

A load of additions and fixes to the string and path classes.

Location:
trunk/foundation
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/foundation/class_c/nomfilepath.c

    r146 r180  
    5252  input the resulting path may not be valid.
    5353
    54   The method returns the NOMPath instance after appending.
     54  The method returns a new NOMPath after appending.
    5555 */
    5656NOM_Scope PNOMPath NOMLINK impl_NOMPath_appendPath(NOMPath* nomSelf, const PNOMPath nomPath, CORBA_Environment *ev)
     
    5959
    6060  if(!nomPath)
    61     return nomSelf;
     61    return (PNOMPath)NOMPath_copy(nomSelf, NULLHANDLE);
    6262
    6363  if(0==NOMPath_length((NOMString*)nomPath, ev))
     
    6969    NOMPath_appendSeparator(nomSelf, ev); /* Make sure current path has a separator */
    7070
    71   return (NOMPath*) NOMPath_appendString((NOMString*) nomSelf, (NOMString*)nomPath, NULLHANDLE);
     71  return (NOMPath*) NOMPath_append((NOMString*) nomSelf, (NOMString*)nomPath, NULLHANDLE);
    7272}
    7373
    7474/*
    7575  Append a separator to the path. If the path already has a separator at the end this method does
    76   nothing other than returning the path.
     76  nothing other than returning a new path object. If the given path has zero length a path object
     77  only holding a separator is returned.
     78 
     79  This method always returns a new instance of a NOMPath owned by the caller.
    7780*/
    7881NOM_Scope PNOMPath NOMLINK impl_NOMPath_appendSeparator(NOMPath* nomSelf, CORBA_Environment *ev)
     
    8083  gchar*  chrTemp;
    8184  gulong len;
    82  
     85
    8386  if((len=NOMPath_length((NOMString*)nomSelf, ev))==0)
    8487    return (NOMPath*)NOMPath_appendCString((NOMString*)nomSelf, G_DIR_SEPARATOR_S, ev);
     
    8790    return (NOMPath*)NOMPath_appendCString( (NOMString*)nomSelf, G_DIR_SEPARATOR_S, ev);
    8891
    89   return nomSelf;
     92  return (PNOMPath)NOMPath_copy(nomSelf, NULLHANDLE);
    9093}
    9194
    9295/*
    9396  Strips the path separator from the end of a path if there's one.
     97
     98  This method always returns a new instance of a NOMPath owned by the caller.
    9499 */
    95100NOM_Scope PNOMPath NOMLINK impl_NOMPath_stripSeparator(NOMPath* nomSelf, CORBA_Environment *ev)
     
    98103  gulong len;
    99104
    100   if((len=NOMPath_length((NOMString*)nomSelf, ev))==0)
    101     return nomSelf;
    102 
    103   chrTemp=NOMPath_getCString((NOMString*)nomSelf, ev);
     105  if((len=NOMPath_length((NOMString*)nomSelf, NULLHANDLE))==0)
     106    return (PNOMPath)NOMPath_copy(nomSelf, NULLHANDLE);
     107
     108  chrTemp=NOMPath_queryCString((NOMString*)nomSelf, NULLHANDLE);
     109
    104110  if(chrTemp[len-1]==G_DIR_SEPARATOR)
    105     return (NOMPath*)NOMPath_truncateString( (NOMString*)nomSelf, len-1, ev);
    106 
    107   return nomSelf;
    108 }
     111    return (NOMPath*)NOMPath_truncate( (NOMString*)nomSelf, len-1, NULLHANDLE);
     112
     113  return (PNOMPath)NOMPath_copy(nomSelf, NULLHANDLE);
     114}
     115
     116/*
     117  Returns TRUE if the given path is absolute.
     118  On OS/2 this means it starts with a letter followed by a colon.
     119*/
     120NOM_Scope CORBA_boolean NOMLINK impl_NOMPath_pathIsAbsolute(NOMPath* nomSelf, CORBA_Environment *ev)
     121{
     122  /* NOMPathData* nomThis=NOMPathGetData(nomSelf); */
     123  gchar* chrString;
     124
     125#ifndef __OS2__
     126#error !!!!! Only implemented for OS/2 !!!!!
     127#endif
     128
     129  if(NOMPath_length(nomSelf, NULLHANDLE)<2)
     130    return FALSE;
     131
     132  chrString=NOMPath_queryCString(nomSelf, NULLHANDLE);
     133
     134  if(!g_ascii_isalpha(chrString[0]) || chrString[1]!=':')
     135    return FALSE;
     136
     137  return TRUE;
     138}
     139
     140NOM_Scope PNOMPath NOMLINK impl_NOMPath_queryRoot(NOMPath* nomSelf, CORBA_Environment *ev)
     141{
     142/* NOMPathData* nomThis=NOMPathGetData(nomSelf); */
     143  PNOMPath nomRetval=(PNOMPath)NOMPath_new(nomSelf, NULLHANDLE);
     144  gchar os2Root[4]="a:"; /* includes padding */
     145  gchar *chrTemp;
     146
     147#ifndef __OS2__
     148#error !!!!! Only implemented for OS/2 !!!!!
     149#endif
     150
     151  if(!NOMPath_pathIsAbsolute(nomSelf, NULLHANDLE))
     152    return nomRetval; /* Return a zero length string */
     153
     154  chrTemp=NOMPath_queryCString(nomSelf, NULLHANDLE);
     155
     156  os2Root[0]=chrTemp[0];
     157  return (PNOMPath) NOMPath_assignCString(nomRetval, os2Root, NULLHANDLE);
     158}
     159
     160/*
     161  This method strips all characters from the beginning of a path till the first
     162  directory separator and also this first separator. If there's no separator in
     163  the path a zero length path is returned.
     164
     165  This method always returns a new instance of a NOMPath owned by the caller.
     166 */
     167NOM_Scope PNOMPath NOMLINK impl_NOMPath_erasePathBegin(NOMPath* nomSelf, CORBA_Environment *ev)
     168{
     169  /* NOMPathData* nomThis=NOMPathGetData(nomSelf); */
     170  PNOMPath nomRetval=(PNOMPath) NOMPath_new(nomSelf, NULLHANDLE);
     171  gchar *chrTemp;
     172
     173  chrTemp=NOMPath_queryCString(nomSelf, NULLHANDLE); /* Not a copy */
     174
     175  while(*chrTemp!='\0' && *chrTemp!=G_DIR_SEPARATOR)
     176    chrTemp++;
     177
     178  if(*chrTemp==G_DIR_SEPARATOR)
     179    chrTemp++;
     180
     181  return (PNOMPath)NOMPath_assignCString(nomRetval, chrTemp, NULLHANDLE);
     182}
     183
     184/*
     185  Returns the part of the path up to the first directory separator ('\' on OS/2).
     186  If there's no directory separator the whole path is returned. This method does
     187  not remove the part from the given path. Use erasePathBegin() to do that.
     188*/
     189NOM_Scope PNOMPath NOMLINK impl_NOMPath_queryPathBegin(NOMPath* nomSelf, CORBA_Environment *ev)
     190{
     191/* NOMPathData* nomThis=NOMPathGetData(nomSelf); */
     192  PNOMPath nomRetval=NOMPathNew();
     193  gchar *chrTemp;
     194
     195  chrTemp=NOMPath_copyCString(nomSelf, NULLHANDLE); /* This is a copy */
     196
     197  while(*chrTemp!='\0' && *chrTemp!=G_DIR_SEPARATOR)
     198    chrTemp++;
     199  *chrTemp='\0';
     200
     201  nomRetval=(PNOMPath)NOMPath_assignCString(nomRetval, chrTemp, NULLHANDLE);
     202
     203  g_free(chrTemp);
     204  return (PNOMPath) nomRetval;
     205}
     206
  • trunk/foundation/class_c/nomstring.c

    r146 r180  
    4545
    4646
    47 NOM_Scope PNOMString NOMLINK impl_NOMString_assignString(NOMString* nomSelf, const PNOMString nomString, CORBA_Environment *ev)
     47NOM_Scope PNOMString NOMLINK impl_NOMString_assign(NOMString* nomSelf, const PNOMString nomString,
     48                                                         CORBA_Environment *ev)
    4849{
    49 /* NOMStringData* nomThis=NOMStringGetData(nomSelf); */
     50  /* NOMStringData* nomThis=NOMStringGetData(nomSelf); */
    5051
    51   NOMString_assignCString(nomSelf, NOMString_getCString(nomString, NULLHANDLE), NULLHANDLE);
     52  NOMString_assignCString(nomSelf, NOMString_queryCString(nomString, NULLHANDLE), NULLHANDLE);
    5253  return nomSelf;
    5354}
    5455
    55 /* Assign a C string to this NOMString */
    56 NOM_Scope PNOMString NOMLINK impl_NOMString_assignCString(NOMString* nomSelf, const CORBA_char * chrString, CORBA_Environment *ev)
     56/* Assign a C string to this NOMString. An initially created NOMString object is empty. */
     57NOM_Scope PNOMString NOMLINK impl_NOMString_assignCString(NOMString* nomSelf, const CORBA_char * chrString,
     58                                                          CORBA_Environment *ev)
    5759{
    5860  NOMStringData* nomThis=NOMStringGetData(nomSelf);
    5961
    60   g_string_assign(_gString, chrString);
     62  g_string_assign(_gString, chrString); /* This copies the input string */
    6163  return nomSelf;
    6264}
    6365
    64 /* Returns the C string held by this NOMString */
    65 NOM_Scope CORBA_string NOMLINK impl_NOMString_getCString(NOMString* nomSelf, CORBA_Environment *ev)
     66/* Returns the C string held by this NOMString. */
     67NOM_Scope CORBA_string NOMLINK impl_NOMString_queryCString(NOMString* nomSelf, CORBA_Environment *ev)
    6668{
    6769  NOMStringData* nomThis=NOMStringGetData(nomSelf);
     
    7072}
    7173
     74/* Returns a copy of the C string held by this NOMString. */
     75NOM_Scope CORBA_string NOMLINK impl_NOMString_copyCString(NOMString* nomSelf, CORBA_Environment *ev)
     76{
     77  NOMStringData* nomThis=NOMStringGetData(nomSelf);
    7278
    73 NOM_Scope PNOMString NOMLINK impl_NOMString_appendString(NOMString* nomSelf, const PNOMString nomString, CORBA_Environment *ev)
     79  return g_strdup(_gString->str);
     80}
     81
     82NOM_Scope PNOMString NOMLINK impl_NOMString_appendCString(NOMString* nomSelf, const CORBA_char * chrString,
     83                                                          CORBA_Environment *ev)
     84{
     85  NOMStringData* nomThis=NOMStringGetData(nomSelf);
     86  PNOMString nomRetval=(PNOMString) NOMString_new(nomSelf, NULLHANDLE);
     87  GString* gStrTmp;
     88
     89  gStrTmp=g_string_new(_gString->str);
     90  g_string_append(gStrTmp, chrString);
     91  NOMString_assignCString(nomRetval, gStrTmp->str, NULLHANDLE);
     92  g_string_free(gStrTmp, TRUE);
     93
     94  return nomRetval;
     95}
     96
     97NOM_Scope PNOMString NOMLINK impl_NOMString_append(NOMString* nomSelf, const PNOMString nomString,
     98                                                         CORBA_Environment *ev)
    7499{
    75100  /*  NOMStringData* nomThis=NOMStringGetData(nomSelf); */
    76101
    77   NOMString_appendCString(nomSelf, NOMString_getCString(nomString, NULLHANDLE), NULLHANDLE);
    78   return nomSelf;
     102  return NOMString_appendCString(nomSelf, NOMString_queryCString(nomString, NULLHANDLE), NULLHANDLE);
    79103}
    80104
    81 NOM_Scope PNOMString NOMLINK impl_NOMString_prependString(NOMString* nomSelf, const PNOMString nomString, CORBA_Environment *ev)
     105NOM_Scope PNOMString NOMLINK impl_NOMString_prepend(NOMString* nomSelf, const PNOMString nomString,
     106                                                          CORBA_Environment *ev)
    82107{
    83108/* NOMStringData* nomThis=NOMStringGetData(nomSelf); */
    84109
    85   NOMString_prependCString(nomSelf, NOMString_getCString(nomString, NULLHANDLE), NULLHANDLE);
    86   return nomSelf;
    87 }
    88 
    89 NOM_Scope PNOMString NOMLINK impl_NOMString_appendCString(NOMString* nomSelf, const CORBA_char * chrString, CORBA_Environment *ev)
    90 {
    91   NOMStringData* nomThis=NOMStringGetData(nomSelf);
    92 
    93   g_string_append(_gString, chrString);
    94   return nomSelf;
     110  return NOMString_prependCString(nomSelf, NOMString_queryCString(nomString, NULLHANDLE), NULLHANDLE);
    95111}
    96112
     
    98114{
    99115  NOMStringData* nomThis=NOMStringGetData(nomSelf);
     116  PNOMString nomRetval=(PNOMString)NOMString_new(nomSelf, NULLHANDLE);
     117  GString* gStrTmp;
    100118
    101   g_string_prepend(_gString, chrString);
     119  gStrTmp=g_string_new(_gString->str);
     120  g_string_prepend(gStrTmp, chrString);
     121  NOMString_assignCString(nomRetval, gStrTmp->str, NULLHANDLE);
     122  g_string_free(gStrTmp, TRUE);
    102123
    103   return nomSelf;
     124  return nomRetval;
    104125}
    105126
     
    111132}
    112133
    113 NOM_Scope PNOMString NOMLINK impl_NOMString_truncateString(NOMString* nomSelf, const CORBA_unsigned_long ulNewLen,
     134NOM_Scope PNOMString NOMLINK impl_NOMString_truncate(NOMString* nomSelf, const CORBA_unsigned_long ulNewLen,
    114135                                                           CORBA_Environment *ev)
    115136{
    116137  NOMStringData* nomThis=NOMStringGetData(nomSelf);
     138  PNOMString nomRetval=(PNOMString)NOMString_new(nomSelf, NULLHANDLE);
     139  GString* gStrTmp;
    117140
    118   g_string_truncate(_gString, ulNewLen);
     141  gStrTmp=g_string_new(_gString->str);
     142  g_string_truncate(gStrTmp, ulNewLen);
     143  NOMString_assignCString(nomRetval, gStrTmp->str, NULLHANDLE);
     144  g_string_free(gStrTmp, TRUE);
    119145
    120   return nomSelf;
     146  return nomRetval;
    121147}
    122148
    123 NOM_Scope PNOMString NOMLINK impl_NOMString_copyString(NOMString* nomSelf, CORBA_Environment *ev)
     149NOM_Scope PNOMString NOMLINK impl_NOMString_copy(NOMString* nomSelf, CORBA_Environment *ev)
    124150{
    125151  /*  NOMStringData* nomThis=NOMStringGetData(nomSelf); */
    126   PNOMString nomRetval=NOMStringNew();
     152  PNOMString nomRetval;
     153  NOMClass* nomCls;
    127154
    128   NOMString_assignString(nomRetval, nomSelf, ev);
     155  /* We don't know which class we're actually. So we can't just create a new NOMString here.
     156     It is possible that we are called by a subclass. So get the class object and let the
     157     class object create the correct class. */
     158  nomCls=NOMObject_nomGetClass((PNOMObject) nomSelf, NULLHANDLE);
     159  nomRetval=(PNOMString)NOMString_new(nomSelf, NULLHANDLE);
     160
     161  NOMString_assign(nomRetval, nomSelf, ev);
    129162
    130163  return nomRetval;
  • trunk/foundation/idl/nomfilepath.idl

    r129 r180  
    4848  PNOMPath appendSeparator();
    4949  PNOMPath stripSeparator();
     50  boolean  pathIsAbsolute();
     51  PNOMPath queryRoot();
     52  PNOMPath erasePathBegin();
     53  PNOMPath queryPathBegin();
    5054};
    5155
  • trunk/foundation/idl/nomstring.idl

    r142 r180  
    4545  NOMCLASSVERSION(1, 0);
    4646
    47   PNOMString assignString(in PNOMString nomString);   
     47  PNOMString assign(in PNOMString nomString);   
    4848  /* Assign a C string to this NOMString */
    4949  PNOMString assignCString(in string chrString);   
    5050  /* Returns the C string held by this NOMString*/
    51   string getCString();
    52   PNOMString appendString(in PNOMString nomString);   
    53   PNOMString prependString(in PNOMString nomString);
     51  string queryCString();
     52  PNOMString append(in PNOMString nomString);   
     53  PNOMString prepend(in PNOMString nomString);
    5454  PNOMString appendCString(in string chrString);   
    5555  PNOMString prependCString(in string chrString);
    5656  unsigned long length();
    57   PNOMString truncateString(in unsigned long ulNewLen);
    58   PNOMString copyString();
     57  PNOMString truncate(in unsigned long ulNewLen);
     58  PNOMString copy();
     59  string copyCString();
    5960
    6061  /* Init and uninit the GString */
Note: See TracChangeset for help on using the changeset viewer.