wex  v20.04.0
Enumerations | Functions
util.h File Reference
#include <bitset>
#include <list>
#include <vector>
#include <wx/combobox.h>
#include <wx/filedlg.h>
#include <wex/dir.h>
#include <wex/stc-data.h>
Include dependency graph for util.h:

Enumerations

enum  { wex::FIRST_OF_AFTER_FROM_BEGIN = 0, wex::FIRST_OF_BEFORE = 1, wex::FIRST_OF_FROM_END = 2 }
 
enum  { wex::STRING_SORT_DESCENDING = 0, wex::STRING_SORT_UNIQUE = 1 }
 
enum  { wex::TRIM_LEFT = 0, wex::TRIM_MID = 1, wex::TRIM_RIGHT = 2 }
 

Functions

const std::string wex::after (const std::string &text, char c, bool first=true)
 Returns string after first or last occurrence of c Returns the whole string if c is not found.
 
const std::string wex::align_text (const std::string_view &lines, const std::string_view &header=std::string(), bool fill_out_with_space=true, bool fill_out=false, const lexer &l=lexer())
 Aligns text. More...
 
std::tuple< bool, const std::string, const std::vector< std::string > > wex::autocomplete_filename (const std::string &text)
 Tries to autocomplete filename, the result is stored in the tuple. More...
 
bool wex::autocomplete_text (const std::string &text, const std::vector< std::string > &v, std::string &s)
 Tries to autocomplete text from a vector of strings, result stored in the string. More...
 
const std::string wex::before (const std::string &text, char c, bool first=true)
 Returns string before first or last occurrence of c Returns the whole string if c is not found.
 
bool wex::browser_search (const std::string &text)
 Launch default browser and search for text. More...
 
bool wex::clipboard_add (const std::string &text)
 Adds data to the clipboard.
 
const std::string wex::clipboard_get ()
 Returns data from the clipboard.
 
template<typename T >
void wex::combobox_as (wxComboBox *cb, const T &t)
 Adds entries to a combobox from a container.
 
void wex::combobox_from_list (wxComboBox *cb, const std::list< std::string > &text)
 Adds entries to a combobox from a list with strings.
 
bool wex::comparefile (const path &file1, const path &file2)
 Compares the files, using comparator set in the config.
 
const std::string wex::ellipsed (const std::string &text, const std::string &control=std::string(), bool ellipse=true)
 Adds an ellipses after text. More...
 
const std::string wex::firstof (const std::string &text, const std::string &chars, const size_t start_pos=0, firstof_t flags=firstof_t().set(FIRST_OF_AFTER_FROM_BEGIN))
 Returns substring after (or before) first occurrence of one of specified chars. More...
 
const std::string wex::get_endoftext (const std::string &text, size_t max_chars=15)
 If text length exceeds max_chars, returns an ellipse prefix followed by the last max_chars from the text, otherwise just returns the text.
 
const std::string wex::get_find_result (const std::string &find_text, bool find_next, bool recursive)
 Returns a search result, that might be shown in the statusbar.
 
int wex::get_iconid (const path &filename)
 Returns the icon index for this filename (uses the file extension to get it). More...
 
int wex::get_number_of_lines (const std::string &text, bool trimmed=false)
 Returns the number of lines in a (trimmed) string. More...
 
const std::string wex::get_string_set (const std::set< std::string > &kset, size_t min_size=0, const std::string &prefix=std::string())
 Returns string from set.
 
std::tuple< bool, time_t > wex::get_time (const std::string &text, const std::string &format=file_stat::MOD_TIME_FORMAT)
 Converts time string into time_t. More...
 
const std::string wex::get_word (std::string &text)
 Returns a word from a string.
 
bool wex::is_brace (int c)
 Returns true if char is a brace open or close character.
 
bool wex::is_codeword_separator (int c)
 Returns true if char is a code word separator.
 
long wex::make (const path &makefile)
 Runs make on specified makefile. More...
 
bool wex::marker_and_register_expansion (const ex *ex, std::string &command)
 Expands all markers and registers in command. More...
 
int wex::match (const std::string &regex, const std::string &text, std::vector< std::string > &v)
 Regular expression match. More...
 
bool wex::matches_one_of (const std::string &fullname, const std::string &patterns)
 Returns true if filename (fullname) matches one of the fields in specified pattern (fields separated by ; sign).
 
void wex::node_properties (const pugi::xml_node *node, std::vector< property > &properties)
 Parses properties node.
 
void wex::node_styles (const pugi::xml_node *node, const std::string &lexer, std::vector< style > &styles)
 Parses style node.
 
bool wex::one_letter_after (const std::string &text, const std::string &letter)
 Returns whether there is one letter after.
 
int wex::open_files (frame *frame, const std::vector< path > &files, const stc_data &data=stc_data(), dir::type_t type=dir::type_t().set())
 Opens all files specified by files. More...
 
void wex::open_files_dialog (frame *frame, long style=wxFD_OPEN|wxFD_MULTIPLE|wxFD_CHANGE_DIR, const std::string &wildcards=wxFileSelectorDefaultWildcardStr, bool ask_for_continue=false, const stc_data &data=stc_data(), dir::type_t type=dir::type_t().set())
 Shows a dialog and opens selected files (calls open_files). More...
 
const std::string wex::print_caption (const path &filename)
 Adds a caption.
 
const std::string wex::print_footer ()
 You can use macros in PrintFooter and in PrintHeader: @PAGENUM@ is replaced by page number @PAGESCNT@ is replaced by total number of pages.
 
const std::string wex::print_header (const path &filename)
 Adds a header.
 
const std::string wex::quoted (const std::string &text)
 Returns quotes around the text.
 
bool wex::regafter (const std::string &text, const std::string &letter)
 Returns true if a register is specified after letter in text.
 
int wex::replace_all (std::string &text, const std::string &search, const std::string &replace, int *match_pos=nullptr)
 Replaces all substrings in text with replace. More...
 
bool wex::shell_expansion (std::string &command)
 Executes all process between backquotes in command, and changes command with replaced match with output from process. More...
 
bool wex::single_choice_dialog (wxWindow *parent, const std::string &title, const wxArrayString &s, std::string &selection)
 Presents a dialog to choose one string out of an array.
 
const std::string wex::sort (const std::string &input, string_sort_t sort_t, size_t pos, const std::string &eol, size_t len=std::string::npos)
 Sorts specified text, returns string with sorted text. More...
 
bool wex::sort_selection (stc *stc, string_sort_t sort_t=0, size_t pos=0, size_t len=std::string::npos)
 Sorts specified component, returns true if sorted ok. More...
 
const std::string wex::translate (const std::string &text, int pageNum, int numPages)
 This takes care of the translation.
 
const std::string wex::trim (const std::string &text, skip_t type_t=skip_t().set(TRIM_LEFT).set(TRIM_RIGHT), const std::string &replace_with=" ")
 Returns a string without all white space in specified input. More...
 
void wex::vcs_command_stc (const vcs_command &command, const lexer &lexer, stc *stc)
 Use specified vcs command to set lexer on stc document. More...
 
void wex::vcs_execute (frame *frame, int id, const std::vector< path > &files)
 Executes VCS command id for specified files and opens component if necessary. More...
 
void wex::xml_error (const path &filename, const pugi::xml_parse_result *result, stc *stc=nullptr)
 Shows xml error. More...
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
FIRST_OF_AFTER_FROM_BEGIN 

substring after match, from begin

FIRST_OF_BEFORE 

substring before match

FIRST_OF_FROM_END 

substring from end

◆ anonymous enum

anonymous enum
Enumerator
STRING_SORT_DESCENDING 

sort descending order

STRING_SORT_UNIQUE 

flag to remove doubles

◆ anonymous enum

anonymous enum
Enumerator
TRIM_LEFT 

skip space at left

TRIM_MID 

skip space at mid

TRIM_RIGHT 

skip space at right

Function Documentation

◆ align_text()

const std::string wex::align_text ( const std::string_view &  lines,
const std::string_view &  header = std::string(),
bool  fill_out_with_space = true,
bool  fill_out = false,
const lexer l = lexer() 
)

Aligns text.

Parameters
lineslines to align
headerThe header is used as a prefix for the line, directly followed by the lines, and if necessary on the next line the header is repeated as a string of spaces.
fill_out_with_spaceif fill out, then use space
fill_outfill out
lif lexer is specified fills out over lexer comment lines If the lexer has no comment end character, fill out with spaces is not done.

◆ autocomplete_filename()

std::tuple< bool, const std::string, const std::vector<std::string> > wex::autocomplete_filename ( const std::string &  text)

Tries to autocomplete filename, the result is stored in the tuple.

Parameters
texttext containing start of a filename

◆ autocomplete_text()

bool wex::autocomplete_text ( const std::string &  text,
const std::vector< std::string > &  v,
std::string &  s 
)

Tries to autocomplete text from a vector of strings, result stored in the string.

Returns true if a unique match was found.

Parameters
texttext to be completed
vvector with completed text
sexpansion of text to one of the strings from the vector

◆ browser_search()

bool wex::browser_search ( const std::string &  text)

Launch default browser and search for text.

Returns false if search engine is empty.

◆ ellipsed()

const std::string wex::ellipsed ( const std::string &  text,
const std::string &  control = std::string(),
bool  ellipse = true 
)

Adds an ellipses after text.

The control, if present is postfixed, after a tab character (for accels).

◆ firstof()

const std::string wex::firstof ( const std::string &  text,
const std::string &  chars,
const size_t  start_pos = 0,
firstof_t  flags = firstof_t().set(FIRST_OF_AFTER_FROM_BEGIN) 
)

Returns substring after (or before) first occurrence of one of specified chars.

Parameters
texttext to be searched
charschars to be found
start_posstart pos (from start or end of text, depending on flags)
flagsstart searching at begin, or at end

◆ get_iconid()

int wex::get_iconid ( const path filename)

Returns the icon index for this filename (uses the file extension to get it).

The return value is an index in wxTheFileIconsTable. You can use this index as a bitmap using: wxTheFileIconsTable->GetSmallImageList()->GetBitmap(get_iconid(file))

◆ get_number_of_lines()

int wex::get_number_of_lines ( const std::string &  text,
bool  trimmed = false 
)

Returns the number of lines in a (trimmed) string.

If text is empty, 0 is returned, otherwise at least 1.

◆ get_time()

std::tuple< bool, time_t> wex::get_time ( const std::string &  text,
const std::string &  format = file_stat::MOD_TIME_FORMAT 
)

Converts time string into time_t.

The result is stored in the tuple.

Parameters
texttext to be converted
formatformat to be used for cnoversion

◆ make()

long wex::make ( const path makefile)

Runs make on specified makefile.

Returns value from executing the make process.

Parameters
makefilethe makefile

◆ marker_and_register_expansion()

bool wex::marker_and_register_expansion ( const ex ex,
std::string &  command 
)

Expands all markers and registers in command.

Returns false if a marker could not be found.

◆ match()

int wex::match ( const std::string &  regex,
const std::string &  text,
std::vector< std::string > &  v 
)

Regular expression match.

Returns:

  • -1 if text does not match or there is an error
  • 0 if text matches, but no submatches present, v is untouched
  • submatches, it fills v with the submatches
Parameters
regexregular expression
texttext to match
vvector is filled with submatches

◆ open_files()

int wex::open_files ( frame frame,
const std::vector< path > &  files,
const stc_data data = stc_data(),
dir::type_t  type = dir::type_t().set() 
)

Opens all files specified by files.

Returns number of files opened.

Parameters
frameframe on which open_file for each file is called, and open_file_dir for each dir
filesarray with files
datadata to be used with open_file
typeflags to be used with open_file_dir

◆ open_files_dialog()

void wex::open_files_dialog ( frame frame,
long  style = wxFD_OPEN|wxFD_MULTIPLE|wxFD_CHANGE_DIR,
const std::string &  wildcards = wxFileSelectorDefaultWildcardStr,
bool  ask_for_continue = false,
const stc_data data = stc_data(),
dir::type_t  type = dir::type_t().set() 
)

Shows a dialog and opens selected files (calls open_files).

Parameters
frameframe
stylestyle for file_dialog dialog
wildcardswilcards for file_dialog dialog
ask_for_continueflags to be used with file_dialog
datadata to be used with open_file
typeflags to be used with open_file_dir

◆ replace_all()

int wex::replace_all ( std::string &  text,
const std::string &  search,
const std::string &  replace,
int *  match_pos = nullptr 
)

Replaces all substrings in text with replace.

Returns number of replacements.

Parameters
texttext to be replaced
searchtext to replace (no regex)
replacereplacement
match_posif not nullptr, position of first match in text

◆ shell_expansion()

bool wex::shell_expansion ( std::string &  command)

Executes all process between backquotes in command, and changes command with replaced match with output from process.

Returns false if process could not be executed.

◆ sort()

const std::string wex::sort ( const std::string &  input,
string_sort_t  sort_t,
size_t  pos,
const std::string &  eol,
size_t  len = std::string::npos 
)

Sorts specified text, returns string with sorted text.

Parameters
inputtext to sort
sort_tsort type
posposition of the first character to be replaced
eoleol to split lines
lennumber of characters to replace string::npos indicates all characters until eol

◆ sort_selection()

bool wex::sort_selection ( stc stc,
string_sort_t  sort_t = 0,
size_t  pos = 0,
size_t  len = std::string::npos 
)

Sorts specified component, returns true if sorted ok.

Parameters
stcComponent with selected text to be sorted
sort_tsort type
posposition of the first character to be replaced
lennumber of characters to replace string::npos indicates all characters until eol

◆ trim()

const std::string wex::trim ( const std::string &  text,
skip_t  type_t = skip_t().set(TRIM_LEFT).set(TRIM_RIGHT),
const std::string &  replace_with = " " 
)

Returns a string without all white space in specified input.

Parameters
texttext with white space to be skipped
type_tkind of skip
replace_withreplace with (only for TRIM_MID)

◆ vcs_command_stc()

void wex::vcs_command_stc ( const vcs_command command,
const lexer lexer,
stc stc 
)

Use specified vcs command to set lexer on stc document.

Parameters
commandVCS command, used to check for diff or open command
lexerlexer to be used
stcstc on which lexer is set

◆ vcs_execute()

void wex::vcs_execute ( frame frame,
int  id,
const std::vector< path > &  files 
)

Executes VCS command id for specified files and opens component if necessary.

Parameters
frameframe on which open_file is called
idVCS menu id to execute
filesfiles on which to operate

◆ xml_error()

void wex::xml_error ( const path filename,
const pugi::xml_parse_result *  result,
stc stc = nullptr 
)

Shows xml error.

Parameters
filenamexml filename that has error
resultresult of parsing describing the error
stcstc component containing the filename