Ignore:
Timestamp:
Dec 1, 2006, 6:12:24 PM (19 years ago)
Author:
cinc
Message:

Added methods to NOMString and NOMPath classes.

Location:
trunk/foundation/class_c
Files:
2 edited

Legend:

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

    r128 r129  
    1313
    1414#include "nomfilepath.ih"
     15/*
     16  Append a path to the string. A path separator will be added to the current path if necessary and the
     17  given string appended. If the given string starts with a separator no additional separator will be
     18  added to the path prior to appending. If the given string starts with a separator and the current
     19  path ends with a separator the ending separator will be removed before appending.
    1520
     21  Note that there's no check if the input string is an absolute path. So if an absolute path is given as
     22  input the resulting path may not be valid.
     23
     24  The method returns the NOMPath instance after appending.
     25 */
    1626NOM_Scope PNOMPath NOMLINK impl_NOMPath_appendPath(NOMPath* nomSelf, const PNOMPath nomPath, CORBA_Environment *ev)
    1727{
    18 /* NOMFilePathData* nomThis=NOMFilePathGetData(nomSelf); */
    19 #warning !!!!! NOMPath_appendPath() is a stub !!!!!
    20   NOMPath_appendString((NOMString*) nomSelf, (NOMString*)nomPath, NULLHANDLE);
     28  gchar*  chrTemp;
     29
     30  if(!nomPath)
     31    return nomSelf;
     32
     33  if(0==NOMPath_length((NOMString*)nomPath, ev))
     34    return NOMPath_appendSeparator(nomSelf, ev);
     35
     36  if(G_DIR_SEPARATOR==chrTemp[0])
     37    NOMPath_stripSeparator(nomSelf, ev);
     38  else
     39    NOMPath_appendSeparator(nomSelf, ev); /* Make sure current path has a separator */
     40
     41  return (NOMPath*) NOMPath_appendString((NOMString*) nomSelf, (NOMString*)nomPath, NULLHANDLE);
     42}
     43
     44/*
     45  Append a separator to the path. If the path already has a separator at the end this method does
     46  nothing other than returning the path.
     47*/
     48NOM_Scope PNOMPath NOMLINK impl_NOMPath_appendSeparator(NOMPath* nomSelf, CORBA_Environment *ev)
     49{
     50  gchar*  chrTemp;
     51  gulong len;
     52 
     53  if((len=NOMPath_length((NOMString*)nomSelf, ev))==0)
     54    return (NOMPath*)NOMPath_appendCString((NOMString*)nomSelf, G_DIR_SEPARATOR_S, ev);
     55
     56  if(G_DIR_SEPARATOR!=chrTemp[len-1])
     57    return (NOMPath*)NOMPath_appendCString( (NOMString*)nomSelf, G_DIR_SEPARATOR_S, ev);
     58
    2159  return nomSelf;
    2260}
    2361
     62/*
     63  Strips the path separator from the end of a path if there's one.
     64 */
     65NOM_Scope PNOMPath NOMLINK impl_NOMPath_stripSeparator(NOMPath* nomSelf, CORBA_Environment *ev)
     66{
     67  gchar*  chrTemp;
     68  gulong len;
     69
     70  if((len=NOMPath_length((NOMString*)nomSelf, ev))==0)
     71    return nomSelf;
     72
     73  chrTemp=NOMPath_getCString((NOMString*)nomSelf, ev);
     74  if(chrTemp[len-1]==G_DIR_SEPARATOR)
     75    return (NOMPath*)NOMPath_truncateString( (NOMString*)nomSelf, len-1, ev);
     76
     77  return nomSelf;
     78}
  • trunk/foundation/class_c/nomstring.c

    r122 r129  
    6262}
    6363
    64 /* Returns the C string held by this NOMString*/
     64/* Returns the C string held by this NOMString */
    6565NOM_Scope CORBA_string NOMLINK impl_NOMString_getCString(NOMString* nomSelf, CORBA_Environment *ev)
    6666{
     
    104104}
    105105
     106NOM_Scope CORBA_unsigned_long NOMLINK impl_NOMString_length(NOMString* nomSelf, CORBA_Environment *ev)
     107{
     108  NOMStringData* nomThis=NOMStringGetData(nomSelf);
     109
     110  return _gString->len;
     111}
     112
     113NOM_Scope PNOMString NOMLINK impl_NOMString_truncateString(NOMString* nomSelf, const CORBA_unsigned_long ulNewLen,
     114                                                           CORBA_Environment *ev)
     115{
     116  NOMStringData* nomThis=NOMStringGetData(nomSelf);
     117
     118  g_string_truncate(_gString, ulNewLen);
     119
     120  return nomSelf;
     121}
     122
     123
    106124NOM_Scope void NOMLINK impl_NOMString_nomInit(NOMString* nomSelf, CORBA_Environment *ev)
    107125{
     
    110128  NOMString_nomInit_parent((NOMObject*)nomSelf,  ev);
    111129
    112   /* Alloc an empty GString */
    113   _gString=g_string_new(NULL);
     130  /* Alloc a zero length GString */
     131  _gString=g_string_new("");
    114132}
    115133
Note: See TracChangeset for help on using the changeset viewer.