pyccel.utilities.strings module

pyccel.utilities.strings module#

Module containing helper functions for managing strings

pyccel.utilities.strings.create_incremented_string(forbidden_exprs, prefix='Dummy', counter=1, name_clash_checker=None)[source]#

Create a new unique string by incrementing a prefix.

This function takes a prefix and a counter and uses them to construct a new name of the form:

prefix_<counter>

Where counter is formatted to fill 4 characters The new name is checked against a list of forbidden expressions. If the constructed name is forbidden then the counter is incremented until a valid name is found.

Parameters:
  • forbidden_exprs (set) – A set of all the values which are not valid solutions to this problem.

  • prefix (str) – The prefix used to begin the string.

  • counter (int) – The expected value of the next name.

  • name_clash_checker (pyccel.naming.languagenameclashchecker.LanguageNameClashChecker) – A class instance providing access to a has_clash function which determines if names clash in a given language.

Returns:

  • name (str) – The incremented string name.

  • counter (int) – The expected value of the next name.

pyccel.utilities.strings.random_string(n)[source]#

Generate a random string.

Generate a random string with length n made of lower case characters and digits.

Parameters:

n (int) – The length of the random string.

Returns:

The random string.

Return type:

str