| 1 |
////////////////////////////////////////////////////////////////////////////// |
| 2 |
////////////////////////////////////////////////////////////////////////////// |
| 3 |
// |
| 4 |
// copyright : (C) 2008 by Eran Ifrah |
| 5 |
// file name : StringUtils.h |
| 6 |
// |
| 7 |
// ------------------------------------------------------------------------- |
| 8 |
// A |
| 9 |
// _____ _ _ _ _ |
| 10 |
// / __ \ | | | | (_) | |
| 11 |
// | / \/ ___ __| | ___| | _| |_ ___ |
| 12 |
// | | / _ \ / _ |/ _ \ | | | __/ _ ) |
| 13 |
// | \__/\ (_) | (_| | __/ |___| | || __/ |
| 14 |
// \____/\___/ \__,_|\___\_____/_|\__\___| |
| 15 |
// |
| 16 |
// F i l e |
| 17 |
// |
| 18 |
// This program is free software; you can redistribute it and/or modify |
| 19 |
// it under the terms of the GNU General Public License as published by |
| 20 |
// the Free Software Foundation; either version 2 of the License, or |
| 21 |
// (at your option) any later version. |
| 22 |
// |
| 23 |
////////////////////////////////////////////////////////////////////////////// |
| 24 |
////////////////////////////////////////////////////////////////////////////// |
| 25 |
#ifndef STRINGUTILS_H |
| 26 |
#define STRINGUTILS_H |
| 27 |
|
| 28 |
#include "asyncprocess.h" |
| 29 |
#include "codelite_exports.h" |
| 30 |
|
| 31 |
#include <wx/arrstr.h> |
| 32 |
#include <wx/string.h> |
| 33 |
|
| 34 |
class WXDLLIMPEXP_CL StringUtils |
| 35 |
{ |
| 36 |
public: |
| 37 |
enum BuildCommandFlags { |
| 38 |
// build a command using only space as the delimiter |
| 39 |
ONE_LINER = (1 << 0), |
| 40 |
|
| 41 |
// include a comment block before the command |
| 42 |
WITH_COMMENT_PREFIX = (1 << 1), |
| 43 |
}; |
| 44 |
|
| 45 |
public: |
| 46 |
/** |
| 47 |
* @brief convert string into std::string |
| 48 |
*/ |
| 49 |
static std::string ToStdString(const wxString& str); |
| 50 |
|
| 51 |
/** |
| 52 |
* @brief remove terminal colours from buffer |
| 53 |
*/ |
| 54 |
static void StripTerminalColouring(const std::string& buffer, std::string& modbuffer); |
| 55 |
/** |
| 56 |
* @brief wxString version. |
| 57 |
* @param buffer |
| 58 |
* @param modbuffer |
| 59 |
*/ |
| 60 |
static void StripTerminalColouring(const wxString& buffer, wxString& modbuffer); |
| 61 |
|
| 62 |
/** |
| 63 |
* @brief add backslash to markdown styling characters |
| 64 |
*/ |
| 65 |
static void DisableMarkdownStyling(wxString& buffer); |
| 66 |
|
| 67 |
/** |
| 68 |
* @brief build argv out of str |
| 69 |
*/ |
| 70 |
static char** BuildArgv(const wxString& str, int& argc); |
| 71 |
|
| 72 |
/** |
| 73 |
* @brief build argv out of str |
| 74 |
*/ |
| 75 |
static wxArrayString BuildArgv(const wxString& str); |
| 76 |
|
| 77 |
/** |
| 78 |
* @brief free argv created by StringUtils::BuildArgv method |
| 79 |
*/ |
| 80 |
static void FreeArgv(char** argv, int argc); |
| 81 |
|
| 82 |
/** |
| 83 |
* @brief given environment string in form of: `a=b;c=d` construct a clEnvList_t |
| 84 |
*/ |
| 85 |
static clEnvList_t BuildEnvFromString(const wxString& envstr); |
| 86 |
|
| 87 |
/** |
| 88 |
* @brief using the current environment variables, resolve the list |
| 89 |
*/ |
| 90 |
static clEnvList_t ResolveEnvList(const clEnvList_t& env_list); |
| 91 |
static clEnvList_t ResolveEnvList(const wxString& envstr); |
| 92 |
|
| 93 |
/** |
| 94 |
* @brief accept command as input string and break it into array of commands |
| 95 |
* the input string can span on multiple lines or use space as the delimiter |
| 96 |
* (or both) |
| 97 |
* Empty lines and lines starting with "#" are ignored |
| 98 |
*/ |
| 99 |
static wxArrayString BuildCommandArrayFromString(const wxString& command); |
| 100 |
|
| 101 |
/** |
| 102 |
* @brief build command string from array of commands |
| 103 |
* @param command the command array |
| 104 |
* @param flags see `StringUtils::BuildCommandFlags` |
| 105 |
*/ |
| 106 |
static wxString BuildCommandStringFromArray(const wxArrayString& command_arr, |
| 107 |
size_t flags = BuildCommandFlags::ONE_LINER); |
| 108 |
}; |
| 109 |
|
| 110 |
#endif // STRINGUTILS_H |