strutil.h
1//-*-C++-*-
2/***************************************************************************
3 *
4 * Copyright (C) 1999 by Willem van Straten
5 * Licensed under the Academic Free License version 2.1
6 *
7 ***************************************************************************/
8// psrchive/Util/genutil/strutil.h
9
10#ifndef __STRING_UTILS_H
11#define __STRING_UTILS_H
12
13#include <sys/types.h>
14#include <stdio.h>
15#include <stdlib.h>
16
17#include <iostream>
18#include <iomanip>
19#include <sstream>
20#include <string>
21#include <vector>
22
23#include "pad.h"
24#include "tostring.h"
25#include "stringtok.h"
26#include "stringcase.h"
27#include "whitespace.h"
28
30bool printable (const std::string& s);
31
32// returns the filename without its path
33std::string basename (const std::string& filename);
34// returns the path preceding a filename
35std::string pathname (const std::string& filename);
37std::string replace_extension (const std::string& filename,
38 const std::string& extension);
39
41std::string time_string (double seconds);
42
43std::vector<std::string>
44stringdecimate(const std::string& wordstr, std::string delimiters);
45
47std::string remove_all (std::string input, char c);
48
49// ///////////////////////////////////////////////////////////
50// reads up to 'nbytes' (or to eof) from 'istr', adding them
51// to 'str'. returns number of bytes read or -1 on error
52// ///////////////////////////////////////////////////////////
53ssize_t
54stringload (std::string* str, std::istream &istr, std::streamsize nbytes=0);
55
56// ///////////////////////////////////////////////////////////
57// reads up to 'nbytes' (or to eof) from 'fptr', adding them
58// to 'str'. returns number bytes read or -1 on error
59// ///////////////////////////////////////////////////////////
60ssize_t
61stringload (std::string* str, FILE* fptr, size_t nbytes=0);
62
63//
64// copy up to nbytes (or to eof) from 'from' to 'to'
65//
66void copy (FILE* from, FILE* to, ssize_t nbytes=-1);
67
68// ///////////////////////////////////////////////////////////
69// fills a vector of std::string with the first word from each line
70// in the file. A line is delimited by \n or commented by #.
71// ///////////////////////////////////////////////////////////
72int stringfload (std::vector<std::string>* lines, const std::string& filename);
73int stringload (std::vector<std::string>* lines, FILE* fptr);
74
75// ///////////////////////////////////////////////////////////
76// fills a vector of std::string with the lines form file.
77// A line is delimited by \n or commented by #.
78// ///////////////////////////////////////////////////////////
79void loadlines (const std::string& filename, std::vector<std::string>& lines);
80
81// ///////////////////////////////////////////////////////////
82// like sprintf, but returns a string
83// ///////////////////////////////////////////////////////////
84std::string stringprintf (const char *fmt ...);
85
86// //////////////////////////////////////////////////////////
87// string_split splits a string setting parameters before and after
88// to the contents before and after the delimiter string
89// before and after will be empty if the delimiter does not exist
90// //////////////////////////////////////////////////////////
91
92void string_split( std::string source, std::string &before, std::string &after, std::string delimiter );
93
94// //////////////////////////////////////////////////////////
95// string_split splits a string setting parameters before and after
96// to the contents before and after the ANY characters in the delim_chars string
97// before and after will be empty if NONE of delim_chars exist
98// //////////////////////////////////////////////////////////
99
100void string_split_on_any ( std::string source, std::string &before, std::string &after, std::string delim_chars );
101
102// split string into an array of strings
103void string_split_on_any ( const std::string& source, std::vector<std::string>& result, std::string delim_chars );
104
105#endif
106

Generated using doxygen 1.14.0