### Install string_editor Gleam Library Source: https://github.com/maxh213/string_editor/blob/main/README.md Command to add the string_editor library as a dependency to a Gleam project using the Gleam package manager. ```sh gleam add string_editor ``` -------------------------------- ### Parsing Configuration Data with Gleam string_editor Source: https://github.com/maxh213/string_editor/blob/main/README.md These Gleam examples show how to extract values from key-value pairs and parse all environment variables from a multi-line string using the `string_editor` library. It also demonstrates counting configuration entries, utilizing `after`, `after_all`, and `count` functions for configuration parsing. ```gleam // Extract values from key=value pairs string_editor.after("DATABASE_URL=postgres://localhost", on: "=") // Ok("postgres://localhost") // Parse all environment variables from a string string_editor.after_all("PORT=3000\nDB_HOST=localhost\nDB_PORT=5432", on: "=") // ["3000\nDB_HOST=localhost\nDB_PORT=5432", "localhost\nDB_PORT=5432", "5432"] // Count configuration entries string_editor.count("key1=value1,key2=value2,key3=value3", of: "=") // 3 ``` -------------------------------- ### APIDOC: Gleam string_editor.before Function Source: https://github.com/maxh213/string_editor/blob/main/README.md API documentation for the `before` function, which returns the part of a string before the first occurrence of a given pattern. Includes parameter types, return type, and examples. ```APIDOC before(string: String, on pattern: String) -> Result(String, Nil) Returns the part of a string before the first occurrence of a given substring. Examples: string_editor.before("hello world", on: " ") // Ok("hello") string_editor.before("no-match", on: "!") // Error(Nil) ``` -------------------------------- ### APIDOC: Gleam string_editor.before_all Function Source: https://github.com/maxh213/string_editor/blob/main/README.md API documentation for the `before_all` function, which returns a list of all parts of a string before each occurrence of a given pattern. Includes parameter types, return type, and examples. ```APIDOC before_all(string: String, on pattern: String) -> List(String) Returns all parts of a string before each occurrence of a given substring. Examples: string_editor.before_all("a.b.c.d", on: ".") // ["a", "a.b", "a.b.c"] string_editor.before_all("hello world", on: "!") // [] ``` -------------------------------- ### APIDOC: Gleam string_editor.between_all Function Source: https://github.com/maxh213/string_editor/blob/main/README.md API documentation for the `between_all` function, which returns a list of all parts of a string between each occurrence of start and the next occurrence of end. Includes parameter types, return type, and examples. ```APIDOC between_all(string: String, from start: String, to end: String) -> List(String) Returns all parts of a string between each occurrence of start and the next occurrence of end. Examples: string_editor.between_all("123", from: "", to: "") // ["1", "3"] string_editor.between_all("no matches here", from: "
", to: "
") // [] ``` -------------------------------- ### APIDOC: Gleam string_editor.between Function Source: https://github.com/maxh213/string_editor/blob/main/README.md API documentation for the `between` function, which returns the part of a string between two given patterns. Finds the first occurrence of `start` and then the first occurrence of `end` after `start`. Includes parameter types, return type, and examples. ```APIDOC between(string: String, from start: String, to end: String) -> Result(String, Nil) Returns the part of a string between two given substrings. Finds the first occurrence of `start` and then the first occurrence of `end` after `start`. Examples: string_editor.between("link", from: "", to: "") // Ok("link") string_editor.between("

title

", from: "

", to: "

") // Error(Nil) ``` -------------------------------- ### APIDOC: Gleam string_editor.before_at Function Source: https://github.com/maxh213/string_editor/blob/main/README.md API documentation for the `before_at` function, which returns the part of a string before the nth occurrence of a given pattern. Includes parameter types, return type, and examples. ```APIDOC before_at(string: String, on pattern: String, at index: Int) -> Result(String, Nil) Returns the part of a string before the nth occurrence of a given substring (0-indexed). Examples: string_editor.before_at("a.b.c.d", on: ".", at: 1) // Ok("a.b") string_editor.before_at("hello world", on: " ", at: 5) // Error(Nil) ``` -------------------------------- ### APIDOC: Gleam string_editor.between_at Function Source: https://github.com/maxh213/string_editor/blob/main/README.md API documentation for the `between_at` function, which returns the part of a string between the nth occurrence of a start pattern and the first occurrence of an end pattern after that. Includes parameter types, return type, and examples. ```APIDOC between_at(string: String, from start: String, to end: String, at index: Int) -> Result(String, Nil) Returns the part of a string between the nth occurrence of start and the first occurrence of end after that (0-indexed for start pattern). Examples: string_editor.between_at("12", from: "", to: "", at: 1) // Ok("2") string_editor.between_at("

title

", from: "

", to: "

", at: 0) // Error(Nil) ``` -------------------------------- ### Manipulating File Paths with Gleam string_editor Source: https://github.com/maxh213/string_editor/blob/main/README.md These Gleam examples illustrate how to extract file names, file extensions, and all directory components from file paths using the `string_editor` library. It also shows how to count directory levels, leveraging `after`, `after_all`, and `count` functions for path parsing. ```gleam // Get filename from path string_editor.after("/home/user/document.txt", on: "/") // Ok("document.txt") // Get file extension string_editor.after("document.txt", on: ".") // Ok("txt") // Get all directory components string_editor.after_all("/home/user/projects/myapp", on: "/") // ["home/user/projects/myapp", "user/projects/myapp", "projects/myapp", "myapp"] // Count directory levels string_editor.count("/home/user/projects/myapp", of: "/") // 4 ``` -------------------------------- ### Processing Log Data with Gleam string_editor Source: https://github.com/maxh213/string_editor/blob/main/README.md These Gleam examples illustrate how to extract timestamps from log entries and count specific error occurrences within log strings using the `string_editor` library. It demonstrates the use of `before_all` and `count` for log analysis. ```gleam // Extract all timestamps from logs string_editor.before_all("2023-01-01 INFO: message\n2023-01-02 ERROR: problem", on: " INFO:") // Would extract timestamp parts before INFO entries // Count error occurrences string_editor.count("INFO: ok\nERROR: fail\nINFO: ok\nERROR: fail", of: "ERROR:") // 2 ``` -------------------------------- ### Extracting Domain from URLs with Gleam string_editor Source: https://github.com/maxh213/string_editor/blob/main/README.md This Gleam example demonstrates how to extract the domain name from a URL string using the `string_editor.between` function. It effectively isolates the domain by specifying the '://' prefix and '/' suffix as delimiters. ```gleam // Extract domain from URL string_editor.between("https://example.com/path", from: "://", to: "/") // Ok("example.com") ``` -------------------------------- ### APIDOC: Gleam string_editor.after_all Function Source: https://github.com/maxh213/string_editor/blob/main/README.md API documentation for the `after_all` function, which returns a list of all parts of a string after each occurrence of a given pattern. Includes parameter types, return type, and examples. ```APIDOC after_all(string: String, on pattern: String) -> List(String) Returns all parts of a string after each occurrence of a given substring. Examples: string_editor.after_all("a.b.c.d", on: ".") // ["b.c.d", "c.d", "d"] string_editor.after_all("hello world", on: "!") // [] ``` -------------------------------- ### APIDOC: Gleam string_editor.after Function Source: https://github.com/maxh213/string_editor/blob/main/README.md API documentation for the `after` function, which returns the part of a string after the first occurrence of a given pattern. Includes parameter types, return type, and examples. ```APIDOC after(string: String, on pattern: String) -> Result(String, Nil) Returns the part of a string after the first occurrence of a given substring. Examples: string_editor.after("hello world", on: " ") // Ok("world") string_editor.after("no-match", on: "!") // Error(Nil) ``` -------------------------------- ### APIDOC: Gleam string_editor.count Function Source: https://github.com/maxh213/string_editor/blob/main/README.md API documentation for the `count` function, which counts occurrences of a substring. Includes parameter types, return type, and examples. ```APIDOC count(string: String, of pattern: String) -> Int Counts the number of occurrences of a substring in a string. Examples: string_editor.count("hello hello world", of: "hello") // 2 string_editor.count("gleam is fun", of: "rust") // 0 string_editor.count("aaaa", of: "aa") // 2 (non-overlapping matches) ``` -------------------------------- ### Extracting Content from HTML/XML with Gleam string_editor Source: https://github.com/maxh213/string_editor/blob/main/README.md These Gleam examples demonstrate how to extract specific content, all occurrences of content between tags, and count tag occurrences within HTML or XML strings using the `string_editor` library. It showcases `between`, `between_all`, and `count` functions for structured text parsing. ```gleam // Extract content from HTML tags string_editor.between("My Page", from: "", to: "") // Ok("My Page") // Extract all link texts from HTML string_editor.between_all("Home About Contact", from: "", to: "") // ["Home", "About", "Contact"] // Count div tags in HTML string_editor.count("
content
more
", of: "
") // 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.