Bash++
Bash++ compiler internal documentation
Functions
explode.cpp File Reference
#include "explode.h"
Include dependency graph for explode.cpp:

Functions

std::vector< std::string > explode (const std::string &input, char delimiter, bool can_escape, int maximum_number_of_elements, bool preserve_empty)
 Splits a string into a vector of strings based on a delimiter.
 

Function Documentation

◆ explode()

std::vector< std::string > explode ( const std::string &  input,
char  delimiter,
bool  can_escape,
int  maximum_number_of_elements,
bool  preserve_empty 
)

Splits a string into a vector of strings based on a delimiter.

This function mimics the behavior of PHP's explode function. It splits the input string into separate strings using the provided delimiter. If can_escape is true, it does not split where the delimiter is backslash-escaped and removes said backslash from the string If maximum_number_of_elements is set to a value greater than zero, it limits how many elements can be split apart. If the limit is reached, the rest of the string is appended to the last element. If maximum_number_of_elements is zero, it splits the string into as many elements as it needs to. If preserve_empty is true, it preserves empty strings in the output vector. E.g, if the input string is "Test,,one,,two,,three" and the delimiter is ",", it will return {"Test", "", "one", "", "two", "", "three"}. If preserve_empty is false, it will return {"Test", "one", "two", "three"}.