")
// 2
```
--------------------------------
### APIDOC: Gleam string_editor.after_at Function
Source: https://github.com/maxh213/string_editor/blob/main/README.md
API documentation for the `after_at` function, which returns the part of a string after the nth occurrence of a given pattern. Includes parameter types, return type, and examples.
```APIDOC
after_at(string: String, on pattern: String, at index: Int) -> Result(String, Nil)
Returns the part of a string after the nth occurrence of a given substring (0-indexed).
Examples:
string_editor.after_at("a.b.c.d", on: ".", at: 1)
// Ok("c.d")
string_editor.after_at("hello world", on: " ", at: 5)
// Error(Nil)
```
--------------------------------
### Development Commands for String Editor
Source: https://github.com/maxh213/string_editor/blob/main/README.md
Commands to run tests and format code for the `string_editor` project using Gleam's build tools.
```sh
gleam test # Run the tests
gleam format # Format the code
```
--------------------------------
### Gleam string_editor: Performance of before() and after() Functions
Source: https://github.com/maxh213/string_editor/blob/main/README.md
This section analyzes the time and space complexity of `string_editor.before()` and `string_editor.after()` functions. It details their O(n) time complexity due to single-pass string splitting and O(k) space complexity for result substrings, highlighting best and worst-case scenarios.
```APIDOC
Functions:
- `before()`
- `after()`
Time Complexity:
- O(n) where n is the length of the input string.
- Uses `string.split_once()` (single pass).
- Stops at first occurrence of pattern.
- Best case: Pattern found early - O(p) where p is position of pattern.
- Worst case: Pattern not found - O(n) full string scan.
Space Complexity:
- O(k) where k is the length of the result substring.
- Returns only the required portion.
- Minimal intermediate allocations.
- Memory usage scales with output size.
Performance Characteristics:
- Utilizes Gleam's standard string operations.
```
--------------------------------
### Gleam string_editor: Performance of between() Function
Source: https://github.com/maxh213/string_editor/blob/main/README.md
This section analyzes the time and space complexity of the `string_editor.between()` function. It explains its O(n) time complexity due to two sequential split operations and O(k) space complexity for extracted content, noting its reliance on `after()` and `before()`.
```APIDOC
Function:
- `between()`
Time Complexity:
- O(n) where n is the length of the input string.
- Makes two sequential calls to underlying split operations.
- First finds start pattern, then searches remainder for end pattern.
- Still linear overall (each character examined at most twice).
- Best case: Both patterns found early - O(p₁ + p₂) where p₁, p₂ are pattern positions.
- Worst case: End pattern not found - O(n) where n is length after start pattern.
Space Complexity:
- O(k) where k is the length of the extracted content.
- Creates one intermediate string (portion after start pattern).
- Final result is a substring of that intermediate string.
- Memory usage remains proportional to output, not total input.
Implementation:
- Built on top of the `after()` and `before()` functions.
```
--------------------------------
### Gleam String Manipulation Basic Usage
Source: https://github.com/maxh213/string_editor/blob/main/README.md
Demonstrates core string manipulation functions from the `string_editor` library in Gleam, including extracting text before, after, and between patterns, counting occurrences, and indexed extraction.
```gleam
import string_editor
pub fn main() -> Nil {
// Extract text before a pattern
let assert Ok("hello") = string_editor.before("hello world", on: " ")
// Extract text after a pattern
let assert Ok("world") = string_editor.after("hello world", on: " ")
// Extract text between two patterns
let assert Ok("content") = string_editor.between("
content
", from: "
", to: "
")
// Count occurrences of a pattern
let count = string_editor.count("hello hello world", of: "hello") // 2
// Extract at specific index
let assert Ok("a.b") = string_editor.before_at("a.b.c.d", on: ".", at: 1)
// Extract all occurrences
let all_before = string_editor.before_all("a.b.c.d", on: ".") // ["a", "a.b", "a.b.c"]
}
```
--------------------------------
### Gleam string_editor: Error Handling for List Functions
Source: https://github.com/maxh213/string_editor/blob/main/README.md
This section outlines the error handling for `string_editor` functions ending with `_all`. It states that these functions always return a `List(String)` and never fail, returning an empty list `[]` when no matches are found.
```APIDOC
Functions:
- `*_all` functions (e.g., `before_all`, `after_all`, `between_all`)
Behavior:
- Always return a `List(String)`.
- Never fail.
- Return an empty list `[]` when no matches are found.
```
--------------------------------
### Gleam string_editor: Error Handling for Result Functions
Source: https://github.com/maxh213/string_editor/blob/main/README.md
This section details the error handling behavior for `string_editor` functions that return `Result(String, Nil)`. It specifies conditions under which `Error(Nil)` is returned, such as when patterns are not found or occur insufficiently, or when `between` patterns are out of order.
```APIDOC
Functions returning `Result(String, Nil)`:
- `before(input: String, on: String) -> Result(String, Nil)`
- `after(input: String, on: String) -> Result(String, Nil)`
- `between(input: String, from: String, to: String) -> Result(String, Nil)`
- `before_at(input: String, on: String, index: Int) -> Result(String, Nil)`
- `after_at(input: String, on: String, index: Int) -> Result(String, Nil)`
- `between_at(input: String, from: String, to: String, index: Int) -> Result(String, Nil)`
Error Conditions (return `Error(Nil)`):
- Pattern not found in the string (`before`, `after`, `between`).
- Pattern doesn't occur enough times (`before_at`, `after_at`, `between_at`).
- For `between` functions, when either the start or end pattern is not found in the correct order.
```
--------------------------------
### Gleam string_editor: Error Handling for Count Function
Source: https://github.com/maxh213/string_editor/blob/main/README.md
This section describes the error handling for the `string_editor.count()` function. It clarifies that `count()` always returns an `Int` and never fails, returning `0` if no matches for the specified pattern are found.
```APIDOC
Function:
- `count(input: String, of: String) -> Int`
Behavior:
- Always returns an `Int`.
- Never fails.
- Returns `0` when no matches are found.
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.