EpcTools
An event based multi-threaded C++ development framework.
eutil.h
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2009-2019 Brian Waters
3 * Copyright (c) 2019 Sprint
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 
18 #ifndef __eutil_h_included
19 #define __eutil_h_included
20 
23 
24 #include <unistd.h>
25 #include <vector>
26 
27 #include "ebase.h"
28 #include "estring.h"
29 
31 class EUtility
32 {
33 public:
39  static Int indexOf(cpStr path, Char search, Int start = 0);
44  static Int indexOfAny(cpStr path, cpStr search);
49  static Int lastIndexOfAny(cpStr path, cpStr search);
54  static std::vector<EString> split(cpStr s, cpStr delims);
63  static EString &replaceAll(EString &str, cpStr srch, size_t srchlen, cpStr rplc, size_t rplclen);
72  static EString replaceAllCopy(const EString &str, cpStr srch, size_t srchlen, cpStr rplc, size_t rplclen);
73 
77  static std::string string_format( const char *format, ... );
81  static void string_format( std::string &dest, const char *format, ... );
82 
86  static Void copy_file( const std::string &dst, const std::string &src ) { copy_file( dst.c_str(), src.c_str() ); }
88  static Void copy_file( const char *dst, const std::string &src ) { copy_file( dst, src.c_str() ); }
90  static Void copy_file( const std::string &dst, const char *src ) { copy_file( dst.c_str(), src ); }
92  static Void copy_file( const char *dst, const char *src );
93 
96  static Void delete_file( const std::string &fn ) { delete_file( fn.c_str() ); }
98  static Void delete_file( const char *fn );
99 
102  static Bool file_exists( cpStr fn ) { return (access(fn,F_OK)!=-1); }
103 
106  static std::string currentTime();
107 
108 private:
109  static void _string_format( std::string &dest, const char *format, va_list &args );
110 };
111 
112 #endif // #define __eutil_h_included
EUtility::currentTime
static std::string currentTime()
Returns a string representation of the current system time.
Definition: eutil.cpp:146
ebase.h
Macros for various standard C library functions and standard includes.
EUtility::indexOf
static Int indexOf(cpStr path, Char search, Int start=0)
Retrieves the byte index of the search value within the supplied path.
Definition: eutil.cpp:25
EUtility::copy_file
static Void copy_file(const char *dst, const std::string &src)
Copies the source file to the destination location.
Definition: eutil.h:88
EUtility::copy_file
static Void copy_file(const std::string &dst, const std::string &src)
Copies the source file to the destination location.
Definition: eutil.h:86
EUtility::string_format
static std::string string_format(const char *format,...)
Formats a string using the supplied format string. Uses printf format specifiers.
Definition: eutil.cpp:125
EUtility
Class that contains various utility functions.
Definition: eutil.h:31
EUtility::file_exists
static Bool file_exists(cpStr fn)
Determines if the supplied file exists.
Definition: eutil.h:102
EUtility::delete_file
static Void delete_file(const std::string &fn)
Deletes the supplied file.
Definition: eutil.h:96
EUtility::lastIndexOfAny
static Int lastIndexOfAny(cpStr path, cpStr search)
Retrieves the last byte index of any of the search values within the supplied path.
Definition: eutil.cpp:54
EUtility::replaceAllCopy
static EString replaceAllCopy(const EString &str, cpStr srch, size_t srchlen, cpStr rplc, size_t rplclen)
replaces all occurances of the search string in the provided string with the replacement string retur...
Definition: eutil.cpp:99
EString
String class.
Definition: estring.h:30
EUtility::copy_file
static Void copy_file(const std::string &dst, const char *src)
Copies the source file to the destination location.
Definition: eutil.h:90
EUtility::indexOfAny
static Int indexOfAny(cpStr path, cpStr search)
Retrieves the byte index of any of the search values within the supplied path.
Definition: eutil.cpp:38
estring.h
Encapsulates and extends a std::string object.
EUtility::replaceAll
static EString & replaceAll(EString &str, cpStr srch, size_t srchlen, cpStr rplc, size_t rplclen)
replaces all occurances of the search string in the provided string with the replacement string.
Definition: eutil.cpp:91
EUtility::split
static std::vector< EString > split(cpStr s, cpStr delims)
Splits a string into substrings that are based on the characters in the delimiter array.
Definition: eutil.cpp:73