Katana Plug-in APIs 0.1

pystring.h

00001 // Copyright (c) 2012 The Foundry Visionmongers Ltd. All Rights Reserved.
00002 
00003 #ifndef INCLUDED_GEOLIB_PYSTRING_V1_H
00004 #define INCLUDED_GEOLIB_PYSTRING_V1_H
00005 
00006 #include <string>
00007 #include <vector>
00008 
00009 #include "pystring/ns.h"
00010 #include "pystring/pystringAPI.h"
00011 
00012 GEOLIB3_PYSTRING_NAMESPACE_ENTER
00013 {
00014 
00023 
00027 
00028 
00029     #define MAX_32BIT_INT 2147483647
00030 
00034     PYSTRING_API std::string capitalize( const std::string & str );
00035 
00039     PYSTRING_API std::string center( const std::string & str, int width );
00040 
00045     PYSTRING_API int count( const std::string & str, const std::string & substr, int start = 0, int end = MAX_32BIT_INT);
00046 
00051     PYSTRING_API bool endswith( const std::string & str, const std::string & suffix, int start = 0, int end = MAX_32BIT_INT );
00052 
00057     PYSTRING_API std::string expandtabs( const std::string & str, int tabsize = 8);
00058 
00064     PYSTRING_API int find( const std::string & str, const std::string & sub, int start = 0, int end = MAX_32BIT_INT  );
00065 
00069     PYSTRING_API int index( const std::string & str, const std::string & sub, int start = 0, int end = MAX_32BIT_INT  );
00070 
00075     PYSTRING_API bool isalnum( const std::string & str );
00076 
00081     PYSTRING_API bool isalpha( const std::string & str );
00082 
00087     PYSTRING_API bool isdigit( const std::string & str );
00088 
00093     PYSTRING_API bool islower( const std::string & str );
00094 
00099     PYSTRING_API bool isspace( const std::string & str );
00100 
00106     PYSTRING_API bool istitle( const std::string & str );
00107 
00112     PYSTRING_API bool isupper( const std::string & str );
00113 
00118     PYSTRING_API std::string join( const std::string & str, const std::vector< std::string > & seq );
00119 
00124     PYSTRING_API std::string ljust( const std::string & str, int width );
00125 
00129     PYSTRING_API std::string lower( const std::string & str );
00130 
00137     PYSTRING_API std::string lstrip( const std::string & str, const std::string & chars = "" );
00138 
00143     PYSTRING_API std::string mul( const std::string & str, int n);
00144 
00151     PYSTRING_API void partition( const std::string & str, const std::string & sep, std::vector< std::string > & result );
00152 
00157     PYSTRING_API std::string replace( const std::string & str, const std::string & oldstr, const std::string & newstr, int count = -1);
00158 
00164     PYSTRING_API int rfind( const std::string & str, const std::string & sub, int start = 0, int end = MAX_32BIT_INT );
00165 
00170     PYSTRING_API int rindex( const std::string & str, const std::string & sub, int start = 0, int end = MAX_32BIT_INT );
00171 
00176     PYSTRING_API std::string rjust( const std::string & str, int width);
00177 
00184     PYSTRING_API void rpartition( const std::string & str, const std::string & sep, std::vector< std::string > & result );
00185 
00191     PYSTRING_API std::string rstrip( const std::string & str, const std::string & chars = "" );
00192 
00198     PYSTRING_API void split( const std::string & str, std::vector< std::string > & result, const std::string & sep = "", int maxsplit = -1);
00199 
00207     PYSTRING_API void rsplit( const std::string & str, std::vector< std::string > & result, const std::string & sep = "", int maxsplit = -1);
00208 
00213     PYSTRING_API void splitlines(  const std::string & str, std::vector< std::string > & result, bool keepends = false );
00214 
00220     PYSTRING_API bool startswith( const std::string & str, const std::string & prefix, int start = 0, int end = MAX_32BIT_INT );
00221 
00227     PYSTRING_API std::string strip( const std::string & str, const std::string & chars = "" );
00228 
00232     PYSTRING_API std::string swapcase( const std::string & str );
00233 
00238     PYSTRING_API std::string title( const std::string & str );
00239 
00245     PYSTRING_API std::string translate( const std::string & str, const std::string & table, const std::string & deletechars = "");
00246 
00250     PYSTRING_API std::string upper( const std::string & str );
00251 
00256     PYSTRING_API std::string zfill( const std::string & str, int width );
00257 
00261     PYSTRING_API std::string slice( const std::string & str, int start = 0, int end = MAX_32BIT_INT);
00262 
00266 
00267 
00268 namespace os
00269 {
00282 #if defined(_WIN32)
00283     static const char* const sep = "\\";
00284     static const char* const pathsep = ";";
00285 #else
00286     static const char* const sep = "/";
00287     static const char* const pathsep = ":";
00288 #endif  // _WIN32
00289 
00290 namespace path
00291 {
00292     using os::sep;
00293     using os::pathsep;
00294 
00295     // The path manipulation function below have three versions.
00296     // Example:
00297     //   join(...)
00298     //   join_nt(...)
00299     //   join_posix(...)
00300     //
00301     // The regular function dispatches to the other versions - based on the OS
00302     // at compile time - to match the result you'd get from the python
00303     // interpreter on the same operating system
00304     //
00305     // Should you want to 'lock off' to a particular version of the string
00306     // manipulation across *all* operating systems, use the version with the
00307     // _OS you are interested in.  I.e., you can use posix style path joining,
00308     // even on Windows, with join_posix.
00309     //
00310     // The naming, (nt, posix) matches the cpython source implementation.
00311 
00315 
00321 
00322     PYSTRING_API std::string basename(const std::string & path);
00323     PYSTRING_API std::string basename_nt(const std::string & path);
00324     PYSTRING_API std::string basename_posix(const std::string & path);
00325 
00329 
00330     PYSTRING_API std::string dirname(const std::string & path);
00331     PYSTRING_API std::string dirname_nt(const std::string & path);
00332     PYSTRING_API std::string dirname_posix(const std::string & path);
00333 
00338 
00339     PYSTRING_API bool isabs(const std::string & path);
00340     PYSTRING_API bool isabs_nt(const std::string & path);
00341     PYSTRING_API bool isabs_posix(const std::string & s);
00342 
00348 
00349     PYSTRING_API std::string abspath(const std::string & path, const std::string & cwd);
00350     PYSTRING_API std::string abspath_nt(const std::string & path, const std::string & cwd);
00351     PYSTRING_API std::string abspath_posix(const std::string & path, const std::string & cwd);
00352 
00353 
00362 
00364     PYSTRING_API std::string join(const std::string & path1, const std::string & path2);
00365     PYSTRING_API std::string join_nt(const std::string & path1, const std::string & path2);
00366     PYSTRING_API std::string join_posix(const std::string & path1, const std::string & path2);
00367 
00368     PYSTRING_API std::string join(const std::vector< std::string > & paths);
00369     PYSTRING_API std::string join_nt(const std::vector< std::string > & paths);
00370     PYSTRING_API std::string join_posix(const std::vector< std::string > & paths);
00371 
00377 
00378     PYSTRING_API std::string normpath(const std::string & path);
00379     PYSTRING_API std::string normpath_nt(const std::string & path);
00380     PYSTRING_API std::string normpath_posix(const std::string & path);
00381 
00390 
00391     PYSTRING_API void split(std::string & head, std::string & tail, const std::string & path);
00392     PYSTRING_API void split_nt(std::string & head, std::string & tail, const std::string & path);
00393     PYSTRING_API void split_posix(std::string & head, std::string & tail, const std::string & path);
00394 
00400 
00401     PYSTRING_API void splitdrive(std::string & drivespec, std::string & pathspec, const std::string & path);
00402     PYSTRING_API void splitdrive_nt(std::string & drivespec, std::string & pathspec, const std::string & p);
00403     PYSTRING_API void splitdrive_posix(std::string & drivespec, std::string & pathspec, const std::string & path);
00404 
00409 
00410     PYSTRING_API void splitext(std::string & root, std::string & ext, const std::string & path);
00411     PYSTRING_API void splitext_nt(std::string & root, std::string & ext, const std::string & path);
00412     PYSTRING_API void splitext_posix(std::string & root, std::string & ext, const std::string & path);
00413 
00421     PYSTRING_API std::string expanduser(const std::string & path);
00422 
00424     class EnvironmentInterface;
00425 
00432     PYSTRING_API std::string expandvars(
00433         const std::string& path,
00434         EnvironmentInterface* environment = NULL);
00435 
00436     class PYSTRING_API EnvironmentInterface
00437     {
00438     public:
00439         virtual ~EnvironmentInterface()
00440         {
00441         }
00442         virtual bool getenv(const std::string& key,
00443                             std::string& result) const = 0;
00444     };
00445 
00449 } // namespace path
00450 } // namespace os
00451 
00452 }
00453 GEOLIB3_PYSTRING_NAMESPACE_EXIT
00454 
00455 #endif  // INCLUDED_GEOLIB_PYSTRING_V1_H
 All Classes Functions Variables Typedefs Enumerations Enumerator