Paths are text strings that contain nodes separated by character separators. Paths are used in many common applications like file system addressing, URLs, etc. so being able to parse them is quite important.
The Path Iterator API is intended for general purpose use and supports UTF-8 null-terminated strings and multi-character separators.
This API can be used to iterate over paths, traversing the path node-by-node. Or creating and combining paths together while ensuring that the resultant paths are properly normalized. For instance the following path:
/a//path/to/a///some/../place
Would be normalized to the path:
/a/path/to/a/place
Before iterating over a path, a path object must first be created by calling either le_pathIter_Create()
, or le_pathIter_CreateForUnix()
. le_pathIter_Create()
will allow you to create an iterator for one of many different path styles. While le_pathIter_CreateForUnix()
will create an iterator preconfigured for Unix style paths.
All strings to this API must be formatted as UTF-8 null-terminated strings.
When the path object is no longer needed, it can be deleted by calling le_pathIter_Delete().
Once an object is created, the nodes in it can be accessed using le_pathIter_GoToNext()
, or le_pathIter_GoToPrev()
. To start over at the beginning of the path call le_pathIter_GoToStart()
. To position the iterator at the end of the path, use le_pathIter_GoToEnd()
. On creation, the default position of the iterator is at the end of the path.
Code sample, iterate over an entire path:
le_pathIter_GetNextNode()
and le_pathIter_GetPreviousNode()
treat consecutive separators as a single separator.Absolute paths begin with one or more separators. Relative paths do not begin with a separator. le_pathIter_IsAbsolute()
can be used to determine if the path is absolute or relative.
In addition to pure iteration, the path iterator can allow you to modify a path. For instance, you can iterate to a node in the path and use le_pathIter_Truncate()
to truncate everything at and after that point. While you can use le_pathIter_Append()
to add new path nodes at the end of the path.
Take the following code:
Note that le_pathIter_Append()
will also normalize paths as it appends. So, the following example has the same effect as the previous one.
Copyright (C) Sierra Wireless Inc. Use of this work is subject to license. license.