TeplUtils: Tepl 4 Reference Manual

## TeplUtils TeplUtils — Utility functions |

## Functions

gchar * | tepl_utils_str_middle_truncate ()
gchar * | tepl_utils_str_end_truncate ()
gchar * | tepl_utils_str_replace ()
gchar * | tepl_utils_get_file_extension ()
gchar * | tepl_utils_get_file_shortname ()
gchar * | tepl_utils_replace_home_dir_with_tilde ()

## Includes

    #include <tepl/tepl.h>

## Description

Utility functions.

## Functions

### tepl_utils_str_middle_truncate ()

    gchar *
    tepl_utils_str_middle_truncate (const gchar *str,
                                    guint truncate_length);

If `str` is longer than `truncate_length` , then this function returns `str` truncated in the middle with a “…” character. Otherwise it just returns a copy of `str` .

#### Parameters

str | a UTF-8 string. |
truncate_length | truncate the string at that length, in UTF-8 characters (not bytes). |

#### Returns

the truncated string. Free with `g_free()`.

Since: 4.4

### tepl_utils_str_end_truncate ()

    gchar *
    tepl_utils_str_end_truncate (const gchar *str,
                                 guint truncate_length);

Like `tepl_utils_str_middle_truncate()` but the “…” character is at the end.

#### Parameters

str | a UTF-8 string. |
truncate_length | truncate the string at that length, in UTF-8 characters (not bytes). |

#### Returns

the truncated string. Free with `g_free()`.

Since: 4.4

### tepl_utils_str_replace ()

    gchar *
    tepl_utils_str_replace (const gchar *string,
                            const gchar *search,
                            const gchar *replacement);

Replaces all occurences of `search` by `replacement` .

The function does only one pass, for example:

    1
    tepl_utils_str_replace ("aaaa", "aa", "a");

returns "aa", not "a".

#### Parameters

string | a string |
search | the search string |
replacement | the replacement string |

#### Returns

A newly allocated string with the replacements. Free with `g_free()`.

Since: 4.4

### tepl_utils_get_file_extension ()

    gchar *
    tepl_utils_get_file_extension (const gchar *filename);

Examples:

- "file.pdf" returns ".pdf".

- "file.PDF" returns ".pdf".

- "file.tar.gz" returns ".gz".

- "path/to/file.pdf" returns ".pdf".

- "file" (without an extension) returns "" (the empty string).

#### Parameters

filename | a filename. |

#### Returns

the `filename` 's extension with the dot, in lowercase. Free with `g_free()`.

Since: 4.4

### tepl_utils_get_file_shortname ()

    gchar *
    tepl_utils_get_file_shortname (const gchar *filename);

Returns `filename` without its extension. With the “extension” having the same definition as in `tepl_utils_get_file_extension()`; in other words it returns the other part of `filename` .

#### Parameters

filename | a filename. |

#### Returns

the `filename` without its extension. Free with `g_free()`.

Since: 4.4

### tepl_utils_replace_home_dir_with_tilde ()

    gchar *
    tepl_utils_replace_home_dir_with_tilde
                                   (const gchar *filename);

Replaces the home directory with a tilde, if the home directory is present in the `filename` .

#### Parameters

filename | the filename. |

#### Returns

the new filename. Free with `g_free()`.

Since: 4.4