# Juliet\include\Core\Common\String

## Source Files
- Header: `Juliet\include\Core\Common\String.h`
- Source: `Juliet\src\Core\Common\String.cpp`

## AI Description
The provided code snippet is a part of a library for string manipulation and encoding in C++. It includes functions to convert strings between different encodings, such as UTF-8, ASCII, Latin1, and others. The `ConvertString` function takes two strings (from and to) and converts the from string into the to string format. It supports various encodings including UTF-8, ASCII, Latin1, and others.

Here's a breakdown of the key components:

### Function Definitions

1. **CaseFoldUnicode**: This function is used to fold Unicode characters according to a specific case folding rule. For simplicity, it only supports low ASCII characters (0-127).

    ```cpp
    int CaseFoldUnicode(const char* str, uint32* folded);
    ```

2. **ConvertString**: This function converts a string from one encoding to another. It first determines the source and destination encodings based on the provided strings.

    ```cpp
    bool ConvertString(StringEncoding from, StringEncoding to, String src, StringBuffer? dst, bool nullTerminate);
    ```

3. **ConvertString**: This is an overloaded version of `ConvertString` that takes a `String` object instead of a `const char*`.

    ```cpp
    bool ConvertString(String from, String to, String src, StringBuffer? dst, bool nullTerminate);
    ```

4. **StringCopy**: This function creates a new string in the provided arena with the same content as the input string.

    ```cpp
    String StringCopy(NonNullPtr?Arena? arena, String str);
    ```

### Helper Functions

1. **StepUTF8**: This function is used to step through UTF-8 encoded characters.

    ```cpp
    const char* StepUTF8(const char* str, size_t? remainingSize);
    ```

2. **StringCompareCaseInsensitive**: This function compares two strings in a case-insensitive manner.

    ```cpp
    int StringCompareCaseInsensitive(String str1, String str2);
    ```

### Encodings

The `Encodings` array contains information about different string encodings supported by the library:

```cpp
const Encoding Encodings[] = {
    { "UTF8", StringEncoding::UTF8 },
    { "Unknown", StringEncoding::Unknown },
    { "ASCII", StringEncoding::ASCII },
    { "LATIN1", StringEncoding::LATIN1 },
    { "UTF16", StringEncoding::UTF16 },
    { "UTF32", StringEncoding::UTF32 },
    { "UCS2", StringEncoding::UCS2 },
    { "UCS4", StringEncoding::UCS4 }
};
```

### Usage Example

Here's an example of how to use the `ConvertString` function:

```cpp
NonNullPtr?Arena? arena = ArenaCreate();
String str1 = "Hello, World!";
String str2

## Symbols

### Namespace `Juliet`

#### Classes, Structs & Unions
- `struct String`
- `struct StringBuffer`
- `struct StringListNode`
- `struct StringList`

#### Enums
- `enum class StringEncoding`

#### Functions & Methods
- `\ MemSet(name##_, 0, sizeof(uint32))`
- `return anonymous::IsValid(FindChar(str, c))`
- `JULIET_API uint32 StepUTF8(String& inStr)`
- `JULIET_API String FindString(String strLeft, String strRight)`
- `// Case insensitive compare. Supports ASCII only
    // TODO: Support UNICODE
    extern JULIET_API int8 StringCompareCaseInsensitive(String str1, String str2)`
- `// Do not allocate anything, you must allocate your out buffer yourself
    // TODO: Version taking arena that can allocate
    // Do not take String type because we dont know the string encoding we are going from/to
    // src and dst will be casted based on the encoding.
    // size will correspond to the number of characters
    // Will convert \0 character if present.
    extern JULIET_API bool ConvertString(StringEncoding from, StringEncoding to, String src, StringBuffer& dst, bool nullTerminate)`
- `extern JULIET_API bool ConvertString(String from, String to, String src, StringBuffer& dst, bool nullTerminate)`
- `JULIET_API String StringCopy(NonNullPtr<Arena> arena, String str)`

