# `sc_crawler.str_utils`

> String helpers, e.g. for wrapping, pluralizing and converting to snake case.

# `sc_crawler.str_utils`

**Functions:**

- [**wrap**](#wrap) – Wrap string between before/after strings (default to spaces) if not empty.
- [**space_after**](#space_after) – Add space after string if not empty.
- [**snake_case**](#snake_case) – Convert CamelCase to snake_case.
- [**plural**](#plural) – Super basic implementation of pluralizing an English word.
- [**extract_last_number**](#extract_last_number) – Extract the last non-negative number from a string.

## func <code class="doc-name">wrap</code> [str_utils.py:7–15](https://github.com/SpareCores/sc-crawler/blob/81bb61ea164dda526de4aa6de298810007274f21/src/sc_crawler/str_utils.py#L7-L15)

```python
wrap(text, before=' ', after=' ')
```

Wrap string between before/after strings (default to spaces) if not empty.

**Parameters:**

- **text** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – A string.
- **before** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Characters to be added before the `text`.
- **after** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Characters to be added after the `text`.

## func <code class="doc-name">space_after</code> [str_utils.py:18–20](https://github.com/SpareCores/sc-crawler/blob/81bb61ea164dda526de4aa6de298810007274f21/src/sc_crawler/str_utils.py#L18-L20)

```python
space_after(text)
```

Add space after string if not empty.

## func <code class="doc-name">snake_case</code> [str_utils.py:24–37](https://github.com/SpareCores/sc-crawler/blob/81bb61ea164dda526de4aa6de298810007274f21/src/sc_crawler/str_utils.py#L24-L37)

```python
snake_case(text)
```

Convert CamelCase to snake_case.

**Parameters:**

- **text** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – A CamelCase text.

**Returns:**

- [`str`](https://docs.python.org/3/builtins/stdtypes.html#str) – snake_case version of the text.

**Examples:**

```pycon
>>> snake_case('DescriptionToComment')
'description_to_comment'
```

## func <code class="doc-name">plural</code> [str_utils.py:41–63](https://github.com/SpareCores/sc-crawler/blob/81bb61ea164dda526de4aa6de298810007274f21/src/sc_crawler/str_utils.py#L41-L63)

```python
plural(text)
```

Super basic implementation of pluralizing an English word.

Note that grammar exceptions are not handled, so better to use a
proper NLP method for real use-cases.

**Parameters:**

- **text** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – A singular noun.

**Returns:**

- [`str`](https://docs.python.org/3/builtins/stdtypes.html#str) – Plural form of the noun.

**Examples:**

```pycon
>>> plural('dog')
'dogs'
>>> plural('boy') # :facepalm:
'boies'
```

## func <code class="doc-name">extract_last_number</code> [str_utils.py:66–82](https://github.com/SpareCores/sc-crawler/blob/81bb61ea164dda526de4aa6de298810007274f21/src/sc_crawler/str_utils.py#L66-L82)

```python
extract_last_number(text)
```

Extract the last non-negative number from a string.

**Parameters:**

- **text** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – The input string from which to extract the number.

**Returns:**

- [`Union`](https://docs.python.org/3/library/typing.html#typing.Union)`[`[`float`](https://docs.python.org/3/builtins/functions.html#float), `None]` – The last non-negative number found in the string, or None if no number is found.

**Examples:**

```pycon
>>> extract_last_number("foo42")
42.0
>>> extract_last_number("foo24.42bar")
24.42
```
