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

Added methods to NOMString and NOMPath classes.

File:
1 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}
Note: See TracChangeset for help on using the changeset viewer.