wex  v21.04.0
Public Member Functions | Static Public Member Functions | List of all members
wex::addressrange Class Reference

Offers an address range for vi (ex). More...

#include <wex/addressrange.h>

Public Member Functions

 addressrange (ex *ex, int lines=1)
 Other methods. More...
 
 addressrange (ex *ex, const std::string &range)
 Constructor for a range (including visual range). More...
 
bool change (const std::string &text) const
 Changes range into text.
 
bool copy (const address &destination) const
 Copies range to destination.
 
bool erase () const
 Deletes range.
 
bool escape (const std::string &command)
 Filters range with command. More...
 
bool execute (const std::string &reg) const
 Executes register on this range.
 
auto & get_begin () const
 Returns begin address.
 
auto & get_end () const
 Returns end address.
 
bool global (const std::string &command, bool inverse=false) const
 Performs the global command on this range. More...
 
bool is_ok () const
 Is this range ok.
 
bool join () const
 joins range.
 
bool move (const address &destination) const
 moves range to destination.
 
bool parse (const std::string &command, const std::string &text, info_message_t &msg)
 Parses this addressrange based on command, and text. More...
 
bool print (const std::string &flags=std::string()) const
 Prints range to print file.
 
const std::string regex_commands () const
 Supported 2addr commands.
 
bool shift_left () const
 Shifts the specified lines to the start of the line.
 
bool shift_right () const
 Shifts the specified lines away from the start of the line.
 
bool sort (const std::string &parameters=std::string()) const
 Sorts range, with optional parameters: -u to sort unique lines -r to sort reversed (descending) More...
 
bool substitute (const std::string &text, char cmd='s')
 substitutes range. More...
 
bool write (const std::string &filename) const
 Writes range to filename.
 
bool yank (char name='0') const
 Yanks range to register, default to yank register.
 

Static Public Member Functions

static void on_exit ()
 Static interface. More...
 

Detailed Description

Offers an address range for vi (ex).

Constructor & Destructor Documentation

◆ addressrange() [1/2]

wex::addressrange::addressrange ( ex ex,
int  lines = 1 
)

Other methods.

Constructor for a range from current position extending with number of lines.

Parameters
exthe ex (or vi) component
lineslines 1 is current line only lines 0 is illegal

◆ addressrange() [2/2]

wex::addressrange::addressrange ( ex ex,
const std::string &  range 
)

Constructor for a range (including visual range).

Parameters
exthe ex (or vi) component
rangethe range, being a string containing:
  • . : current line
  • % : entire document
  • * : current screen visible area
  • x,y : range from begin x and end y address.
  • : (empty), the range is empty

Member Function Documentation

◆ escape()

bool wex::addressrange::escape ( const std::string &  command)

Filters range with command.

The address range is used as input for the command, and the output of the command replaces the address range. For example: addressrange(96, 99).escape("sort") or (ex command::96,99!sort) will pass lines 96 through 99 through the sort filter and replace those lines with the output of sort. Of course, you could also do: addressrange(96,99).Sort(). If you did not specify an address range, the command is run as an asynchronous process.

◆ global()

bool wex::addressrange::global ( const std::string &  command,
bool  inverse = false 
) const

Performs the global command on this range.

Parameters
commandcommand
inversenormally performs command on each match, if inverse performs command if line does not match

◆ on_exit()

static void wex::addressrange::on_exit ( )
static

Static interface.

Cleans up (process).

◆ parse()

bool wex::addressrange::parse ( const std::string &  command,
const std::string &  text,
info_message_t &  msg 
)

Parses this addressrange based on command, and text.

Returns true if command is valid.

Parameters
commandmostly a one letter string like "p" for print
texttext, as required by command
msgextra information in case command failed

◆ sort()

bool wex::addressrange::sort ( const std::string &  parameters = std::string()) const

Sorts range, with optional parameters: -u to sort unique lines -r to sort reversed (descending)

  • x,y sorts rectangle within range: x start col, y end col (exclusive).

◆ substitute()

bool wex::addressrange::substitute ( const std::string &  text,
char  cmd = 's' 
)

substitutes range.

Parameters
texttext format: /pattern/replacement/options Pattern might contain:
  • $ to match a line end Replacement might contain:
  • & or \0 to represent the target in the replacement
  • \U to convert target to uppercase
  • \L to convert target to lowercase Options can be:
  • c : Ask for confirm
  • i : Case insensitive
  • g : Do global on line, without this flag replace first match only e.g. /$/EOL appends the string EOL at the end of each line. Merging is not yet possible using a
    target, you can create a macro for that.
cmdcmd is one of s, & or ~
  • s : default, normal substitute
  • & : repeat last substitute (text contains options)
  • ~ : repeat last substitute with pattern from find replace data (text contains options)