### Install and Use Decancer Go Bindings
Source: https://github.com/null8626/decancer/blob/main/bindings/go/README.md
Demonstrates how to clone the repository, generate the Go bindings, install the library, and then use its core functionalities like curing strings, checking equality, and searching for substrings. Requires administrator privileges for `go generate` on some platforms.
```console
git clone https://github.com/null8626/decancer.git --branch v4.0.0 --depth 1
cd decancer/bindings/go
sudo -E "PATH=$PATH" go generate
go install
```
```go
package main
import (
"os"
"fmt"
"strconv"
"github.com/null8626/decancer/bindings/go"
)
func main() {
cured, err := decancer.Cure("vEⓡ𝔂 𝔽𝕌Ňℕy ţ乇𝕏𝓣", decancer.Default)
if err != nil {
fmt.Fprintln(os.Stderr, "error:", err)
os.Exit(1)
}
defer cured.Close()
fmt.Println(cured.String())
if cured.Equals("very funny text") {
fmt.Println("it is indeed a very funny text")
}
if cured.StartsWith("very") {
fmt.Println("it starts with 'very'")
}
if cured.EndsWith("text") {
fmt.Println("it ends with 'text'")
}
if cured.Contains("funny") {
fmt.Println("it has the funny")
}
funnyMatches := cured.Find("funny")
fmt.Println("funny counter:")
for i, match := range funnyMatches {
fmt.Println("Match " + strconv.Itoa(i) + ":")
fmt.Println(" - start: " + strconv.Itoa(match.Start))
fmt.Println(" - end: " + strconv.Itoa(match.End))
}
keywords := []string{"very", "funny"}
veryFunnyMatches, err := cured.FindMultiple(keywords)
if err != nil {
fmt.Fprintln(os.Stderr, "error:", err)
os.Exit(1)
}
fmt.Println("very funny counter:")
for i, match := range veryFunnyMatches {
fmt.Println("Match " + strconv.Itoa(i) + ":")
fmt.Println(" - start: " + strconv.Itoa(match.Start))
fmt.Println(" - end: " + strconv.Itoa(match.End))
}
}
```
--------------------------------
### Project Setup and Configuration
Source: https://github.com/null8626/decancer/blob/main/bindings/native/tests/CMakeLists.txt
Initializes the CMake project, specifying the minimum version, project name, language, homepage, and description. Sets the build type to Debug.
```cmake
cmake_minimum_required(VERSION 3.8.2)
project(
decancer_native_test
LANGUAGES C
HOMEPAGE_URL "https://github.com/null8626/decancer"
DESCRIPTION "Test suite for the native binding of the decancer library."
)
set(CMAKE_BUILD_TYPE Debug)
```
--------------------------------
### Install decancer via npm
Source: https://github.com/null8626/decancer/blob/main/bindings/node/README.md
Install the decancer package using npm. This command should be run in your shell.
```bash
npm install decancer
```
--------------------------------
### Pretty source code files
Source: https://github.com/null8626/decancer/blob/main/CONTRIBUTING.md
This script formats source code files for consistency. It requires clang-format and Rust to be installed. Ensure prerequisites are met before execution.
```bash
node scripts/pretty.mjs
```
--------------------------------
### Browser-based Text Curing with WebAssembly
Source: https://github.com/null8626/decancer/blob/main/README.md
Integrates decancer via WebAssembly in a browser environment. This example demonstrates a simple textarea input that gets cured when a button is clicked.
```html
Decancerer!!! (tm)
Input cancerous text here:
```
--------------------------------
### C UTF-8 Example
Source: https://github.com/null8626/decancer/blob/main/README.md
Demonstrates basic UTF-8 text curing and checking for containment using the decancer C API. Ensure proper error handling and resource deallocation.
```c
#include
#include
#include
#include
#define decancer_assert(expr, notes) \
if (!(expr)) { \
fprintf(stderr, "assertion failure at " notes "\n"); \
ret = 1; \
goto END; \
}
int main() {
int ret = 0;
// UTF-8 bytes for "vEⓡ𝔂 𝔽𝕌Ňℕy ţ乇𝕏𝓣"
unsigned char input[] = {
0x76, 0xe2, 0x84, 0x95, 0xc5, 0xa3, 0xe4, 0xb9, 0x87, 0xf0, 0x9d, 0x95, 0x8c,
0xc5, 0x87, 0xe2, 0x84, 0x95, 0xef, 0xbd, 0x99, 0x20, 0xc5, 0xa3, 0xe4, 0xb9, 0x87,
0xf0, 0x9d, 0x95, 0x8f, 0xf0, 0x9d, 0x93, 0xa3
};
decancer_error_t error;
decancer_cured_t cured = decancer_cure(input, sizeof(input), DECANCER_OPTION_DEFAULT, &error);
if (cured == NULL) {
fprintf(stderr, "curing error: %.*s\n", (int)error.message_length, error.message);
return 1;
}
decancer_assert(decancer_contains(cured, "funny", 5), "decancer_contains");
END:
decancer_cured_free(cured);
return ret;
}
```
--------------------------------
### Install decancer via Cargo.toml
Source: https://github.com/null8626/decancer/blob/main/core/README.md
Add this line to your Cargo.toml file to include the decancer library in your Rust project.
```toml
decancer = "4.0.0"
```
--------------------------------
### Build Java from Source (Windows)
Source: https://github.com/null8626/decancer/blob/main/README.md
Build the decancer Java library from source on Windows by cloning the repository, navigating to the directory, and running the Gradle build command.
```bat
> git clone https://github.com/null8626/decancer.git --branch v4.0.0 --depth 1
> cd decancer/bindings/java
> powershell -NoLogo -NoProfile -NonInteractive -Command "Expand-Archive -Path .\bin\bindings.zip -DestinationPath .\bin -Force"
> gradle build -x test
```
--------------------------------
### Pre-building decancer Options
Source: https://context7.com/null8626/decancer/llms.txt
Demonstrates how to pre-build a numeric options bitfield using `decancer.options()` for efficient reuse across multiple `decancer()` calls.
```javascript
const decancer = require('decancer')
const myOptions = decancer.options({
retainCapitalization: true,
disableBidi: true,
retainChinese: true,
retainJapanese: true
})
const a = decancer('héllo', myOptions)
const b = decancer('Wörld', myOptions)
console.log(a.toString()) // 'Hello'
console.log(b.toString()) // 'World'
```
--------------------------------
### Build Native Bindings from Source
Source: https://github.com/null8626/decancer/blob/main/bindings/native/README.md
Clone the repository and build the release version of the native bindings using Cargo. The compiled binaries will be located in the `target/release` directory.
```bash
git clone https://github.com/null8626/decancer.git --branch v4.0.0 --depth 1
cd decancer/bindings/native
cargo build --release
```
--------------------------------
### Basic decancer usage and assertions
Source: https://github.com/null8626/decancer/blob/main/bindings/node/README.md
Demonstrates basic usage of the decancer library, including curing a string, comparing it with an expected output, and converting the result to a string. Note that direct string coercion is not recommended for comparison due to custom matching logic.
```javascript
const assert = require('assert')
const cured = decancer('vEⓡ𝔂 𝔽𝕌Ňℕy ţ乇𝕏𝓣 wWiIiIIttHh l133t5p3/-\|<')
assert(cured.equals('very funny text with leetspeak'))
// WARNING: it's NOT recommended to coerce this output to a JavaScript string
// and process it manually from there, as decancer has its own
// custom comparison measures, including leetspeak matching!
assert(cured.toString() !== 'very funny text with leetspeak')
console.log(cured.toString())
// => very funny text wwiiiiitthh l133t5p3/-\|<
assert(cured.contains('funny'))
cured.censor('funny', '*')
console.log(cured.toString())
// => very ***** text wwiiiiitthh l133t5p3/-\|<
cured.censorMultiple(['very', 'text'], '-')
console.log(cured.toString())
// => ---- ***** ---- wwiiiiitthh l133t5p3/-\|<
```
--------------------------------
### Build Java from Source (macOS/Linux)
Source: https://github.com/null8626/decancer/blob/main/README.md
Build the decancer Java library from source on macOS or Linux by cloning the repository, navigating to the directory, unzipping binaries, and running the Gradle build command.
```console
git clone https://github.com/null8626/decancer.git --branch v4.0.0 --depth 1
cd decancer/bindings/java
unzip ./bin/bindings.zip -d ./bin
chmod +x ./gradlew
./gradlew build -x test
```
--------------------------------
### Options
Source: https://context7.com/null8626/decancer/llms.txt
A configuration bitfield for customizing curing and comparison behavior.
```APIDOC
## Options
### Description
A copy type that chains option flags to customize curing and comparison behavior. Provides presets like `ALL`, `PURE_HOMOGLYPH`, and methods to configure specific behaviors.
### Method
- `default() -> Options`
- `retain_capitalization() -> Options`
- `disable_bidi() -> Options`
- `retain_chinese() -> Options`
- `retain_japanese() -> Options`
- `retain_korean() -> Options`
- `retain_arabic() -> Options`
- `retain_hebrew() -> Options`
- `retain_emojis() -> Options`
- `ascii_only() -> Options`
- `alphanumeric_only() -> Options`
### Usage
Instantiate `Options` and chain methods to set desired configurations. Pass the configured `Options` object to the `decancer::cure()` function.
### Request Example
```rust
use decancer::Options;
// Retain specific scripts, disable bidi for speed
let options = Options::default()
.retain_capitalization()
.disable_bidi()
.retain_chinese()
.retain_japanese()
.retain_korean()
.retain_arabic()
.retain_hebrew()
.retain_emojis();
let cured = decancer::cure("héllo wörld", options).unwrap();
// ASCII-only output
let ascii_opts = Options::default().ascii_only();
let cured2 = decancer::cure("héllo", ascii_opts).unwrap();
// Alphanumeric-only
let alnum_opts = Options::default().alphanumeric_only();
let cured3 = decancer::cure("hello, world!", alnum_opts).unwrap();
// Pure homoglyph mode
let cured4 = decancer::cure("héllo", Options::PURE_HOMOGLYPH).unwrap();
// All options enabled
let _all = Options::ALL;
```
### Response
Returns a configured `Options` object that can be used with `decancer::cure()`.
```
--------------------------------
### Load JavaScript (Browser) Module
Source: https://github.com/null8626/decancer/blob/main/README.md
Initialize the decancer library in a browser environment using a script tag and the provided CDN URL.
```html
```
--------------------------------
### Source File Discovery and Executable Creation
Source: https://github.com/null8626/decancer/blob/main/bindings/native/tests/CMakeLists.txt
Globally finds all .c files in the current directory and adds them to the decancer_native_test executable.
```cmake
file(GLOB DECANCER_NATIVE_TEST_SOURCE_FILES *.c)
add_executable(decancer_native_test ${DECANCER_NATIVE_TEST_SOURCE_FILES})
```
--------------------------------
### Convert binary to readable text file
Source: https://github.com/null8626/decancer/blob/main/CONTRIBUTING.md
Use this script to convert the decancer binary data into a human-readable text file. Specify the output file path.
```bash
node scripts/read.mjs path/to/output.txt
```
--------------------------------
### Basic String Curing with decancer
Source: https://context7.com/null8626/decancer/llms.txt
Demonstrates basic string curing, assertion of cured string properties like equals, contains, startsWith, and endsWith. Also shows how to convert the cured string to its string representation.
```javascript
const decancer = require('decancer')
const assert = require('assert')
// Basic cure
const cured = decancer('vEⓡ𝔂 𝔽𝕌Ňℕy ţ乇𝕏𝓣 wWiIiIIttHh l133t5p3/-\|<')
assert(cured.equals('very funny text with leetspeak'))
console.log(cured.toString())
// => very funny text wwiiiiitthh l133t5p3/-\|<
```
--------------------------------
### Validate, optimize, and convert JSON to binary
Source: https://github.com/null8626/decancer/blob/main/CONTRIBUTING.md
Use this script to process a JSON input file, validating, optimizing, and converting it back into the decancer binary format. Provide the path to the input JSON file.
```bash
node scripts/write.mjs path/to/input.json
```
--------------------------------
### Build Go Bindings for Decancer
Source: https://github.com/null8626/decancer/blob/main/README.md
Builds the Go bindings for decancer. Requires Rust v1.65 or later and Go v1.17 or later. Windows systems may require a MinGW compiler. This process often requires elevated administrator permissions.
```console
git clone https://github.com/null8626/decancer.git --branch v4.0.0 --depth 1
cd decancer/bindings/go
sudo -E "PATH=$PATH" go generate
go install
```
--------------------------------
### Go Text Curing and Analysis
Source: https://github.com/null8626/decancer/blob/main/README.md
Demonstrates curing text and performing various analyses like string conversion, equality checks, prefix/suffix checks, containment, and finding multiple keyword occurrences using the decancer Go bindings. Remember to close the cured object to free resources.
```go
package main
import (
"os"
"fmt"
"strconv"
"github.com/null8626/decancer/bindings/go"
)
func main() {
cured, err := decancer.Cure("vEⓡ𝔂 𝔽𝕌Ňℕy ţ乇𝕏𝓣", decancer.Default)
if err != nil {
fmt.Fprintln(os.Stderr, "error:", err)
os.Exit(1)
}
defer cured.Close()
fmt.Println(cured.String())
if cured.Equals("very funny text") {
fmt.Println("it is indeed a very funny text")
}
if cured.StartsWith("very") {
fmt.Println("it starts with 'very'")
}
if cured.EndsWith("text") {
fmt.Println("it ends with 'text'")
}
if cured.Contains("funny") {
fmt.Println("it has the funny")
}
funnyMatches := cured.Find("funny")
fmt.Println("funny counter:")
for i, match := range funnyMatches {
fmt.Println("Match " + strconv.Itoa(i) + ":")
fmt.Println(" - start: " + strconv.Itoa(match.Start))
fmt.Println(" - end: " + strconv.Itoa(match.End))
}
keywords := []string{"very", "funny"}
veryFunnyMatches, err := cured.FindMultiple(keywords)
if err != nil {
fmt.Fprintln(os.Stderr, "error:", err)
os.Exit(1)
}
fmt.Println("very funny counter:")
for i, match := range veryFunnyMatches {
fmt.Println("Match " + strconv.Itoa(i) + ":")
fmt.Println(" - start: " + strconv.Itoa(match.Start))
fmt.Println(" - end: " + strconv.Itoa(match.End))
}
}
```
--------------------------------
### Include Directories and Library Linking
Source: https://github.com/null8626/decancer/blob/main/bindings/native/tests/CMakeLists.txt
Configures the include paths for the test executable and links the found decancer library to it.
```cmake
target_include_directories(decancer_native_test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} "${CMAKE_CURRENT_SOURCE_DIR}/..")
target_link_libraries(decancer_native_test ${DECANCER_LIBRARY})
```
--------------------------------
### Using decancer with Custom Options
Source: https://context7.com/null8626/decancer/llms.txt
Illustrates how to use decancer with an options object to retain capitalization or convert strings to ASCII-only or alphanumeric-only.
```javascript
// Options object
const cured2 = decancer('decÁncer', { retainCapitalization: true })
assert.strictEqual(cured2.toString(), 'decAncer')
```
```javascript
// ASCII-only and alphanumeric-only options
const cured3 = decancer('héllo, wörld!', { asciiOnly: true })
assert.strictEqual(cured3.toString(), 'hello, world!')
```
```javascript
const cured4 = decancer('héllo, wörld!', { alphanumericOnly: true })
assert.strictEqual(cured4.toString(), 'helloworld')
```
--------------------------------
### Update README files for bindings
Source: https://github.com/null8626/decancer/blob/main/CONTRIBUTING.md
Run this script after modifying the root README file to ensure all binding READMEs are up-to-date. This is a maintenance task for project documentation.
```bash
node scripts/readme.mjs
```
--------------------------------
### Curing Strings with Go API
Source: https://context7.com/null8626/decancer/llms.txt
Demonstrates the basic usage of the `decancer.Cure` function in Go, including error handling, freeing resources, and checking string properties.
```go
package main
import (
"fmt"
"os"
"strconv"
"github.com/null8626/decancer/bindings/go"
)
func main() {
cured, err := decancer.Cure("vEⓡ𝔂 𝔽𝕌Ňℕy ţ乇𝕏𝓣", decancer.Default)
if err != nil {
fmt.Fprintln(os.Stderr, "error:", err)
os.Exit(1)
}
defer cured.Close() // must free the underlying C allocation
fmt.Println(cured.String())
// => very funny text
fmt.Println(cured.Equals("very funny text")) // true
fmt.Println(cured.StartsWith("very")) // true
fmt.Println(cured.EndsWith("text")) // true
fmt.Println(cured.Contains("funny")) // true
// Find all occurrences of a keyword
for i, m := range cured.Find("funny") {
fmt.Printf("Match %d: start=%d end=%d\n", i, m.Start, m.End)
}
// FindMultiple with overlap merging
keywords := []string{"very", "funny"}
multi, err := cured.FindMultiple(keywords)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
for i, m := range multi {
fmt.Printf("Multi match %d: %d..%d\n", i, m.Start, m.End)
}
// Censor in-place
if err = cured.Censor("funny", '*'); err != nil {
fmt.Fprintln(os.Stderr, err)
}
fmt.Println(cured.String()) // "very ***** text"
// Replace in-place
if err = cured.Replace("very", "super"); err != nil {
fmt.Fprintln(os.Stderr, err)
}
fmt.Println(cured.String()) // "super ***** text"
// Custom options: retain capitalization + disable bidi
opts := decancer.Option(decancer.RetainCapitalization | decancer.DisableBidi)
cured2, err := decancer.Cure("Héllo", opts)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
defer cured2.Close()
fmt.Println(cured2.String()) // "Hello"
_ = strconv.Itoa(0) // suppress unused import
}
```
--------------------------------
### UTF-8 Text Processing in C/C++
Source: https://github.com/null8626/decancer/blob/main/README.md
Demonstrates basic UTF-8 text processing using the decancer C library. Includes a custom assertion macro for error handling.
```c
#include
#include
#include
#include
#define decancer_assert(expr, notes) \
if (!(expr)) { \
fprintf(stderr, "assertion failure at " notes "\n"); \
ret = 1; \
goto END; \
}
int main() {
int ret = 0;
// UTF-8 bytes for "vEⓡ𝔂 𝔽𝕌Ňℕy ţ乇𝕏𝓣"
uint8_t input[] = {0x76, 0xef, 0xbc, 0xa5, 0xe2, 0x93, 0xa1, 0xf0, 0x9d, 0x94, 0x82, 0x20, 0xf0, 0x9d,
```
--------------------------------
### Post-Build Execution Command
Source: https://github.com/null8626/decancer/blob/main/bindings/native/tests/CMakeLists.txt
Executes the built decancer_native_test executable after the build process is finished. This is typically used to run the test suite.
```cmake
add_custom_command(
TARGET decancer_native_test POST_BUILD
COMMAND decancer_native_test
)
```
--------------------------------
### options(opts?) — Pre-build an options number (JavaScript)
Source: https://context7.com/null8626/decancer/llms.txt
A utility function in JavaScript to convert an options object into a numeric bitfield for efficient reuse across multiple `decancer()` calls.
```APIDOC
## options(opts?)
### Description
Converts an options object into a numeric bitfield for reuse.
### Parameters
- **opts** (object, optional) - An object containing configuration options like `retainCapitalization`, `disableBidi`, etc.
### Returns
- number - A numeric bitfield representing the provided options.
### Example
```javascript
const decancer = require('decancer');
const myOptions = decancer.options({
retainCapitalization: true,
disableBidi: true
});
const a = decancer('héllo', myOptions);
console.log(a.toString()); // 'Hello'
```
```
--------------------------------
### Curing a Single Rune with Go API
Source: https://context7.com/null8626/decancer/llms.txt
Shows how to use `decancer.CureChar` in Go to cure a single rune. Demonstrates that diacritics are stripped.
```go
package main
import (
"fmt"
"github.com/null8626/decancer/bindings/go"
)
func main() {
result := decancer.CureChar('𝔽', decancer.Default) // fullwidth F
fmt.Println(result) // "f"
result2 := decancer.CureChar('\u0301', decancer.Default) // combining acute
fmt.Println(result2 == "") // true — diacritics are stripped
}
```
--------------------------------
### Configuring decancer with Options bitfield
Source: https://context7.com/null8626/decancer/llms.txt
Customize curing and comparison behavior using a chainable Options bitfield. Options include retaining capitalization, Chinese, Japanese, Korean, Arabic, Hebrew, emojis, and ASCII-only output.
```rust
use decancer::Options;
// Retain specific scripts, disable bidi for speed (LTR-only input)
let options = Options::default()
.retain_capitalization()
.disable_bidi()
.retain_chinese()
.retain_japanese()
.retain_korean()
.retain_arabic()
.retain_hebrew()
.retain_emojis();
let cured = decancer::cure("héllo wörld", options).unwrap();
assert_eq!(&*cured, "Hello world"); // capitalization preserved
```
```rust
// ASCII-only output: strips all non-ASCII after translation
let ascii_opts = Options::default().ascii_only();
let cured2 = decancer::cure("héllo", ascii_opts).unwrap();
assert_eq!(&*cured2, "hello");
```
```rust
// Alphanumeric-only: strips punctuation and spaces
let alnum_opts = Options::default().alphanumeric_only();
let cured3 = decancer::cure("hello, world!", alnum_opts).unwrap();
assert_eq!(&*cured3, "helloworld");
```
```rust
// Pure homoglyph mode: only cure Latin-look-alike confusables
let cured4 = decancer::cure("héllo", Options::PURE_HOMOGLYPH).unwrap();
```
```rust
// Enable all options at once
let _all = Options::ALL;
```
--------------------------------
### Convert binary to readable JSON
Source: https://github.com/null8626/decancer/blob/main/CONTRIBUTING.md
This script converts decancer binary data into a JSON format. If no output file is specified, it defaults to 'output.json'.
```bash
node scripts/read.mjs [path/to/output.json]
```
--------------------------------
### Rust: Cure a full string with default options
Source: https://context7.com/null8626/decancer/llms.txt
Use the `cure!` macro for a convenient way to normalize an entire string using default options. This includes lowercasing, bidi awareness, and curing all scripts. The result is a `CuredString` wrapper for fuzzy comparisons.
```rust
use decancer::Options;
// Default: all lowercase, bidi-aware, all scripts cured
let mut cured = decancer::cure!(r"vEⓡ𝔂 𝔽𝕌Ňℕy ţ乇𝕏𝓣 wWiIiIIttHh l133t5p3/-\\|<").unwrap();
// Fuzzy equality (includes leetspeak matching)
assert_eq!(cured, "very funny text with leetspeak");
// NOTE: raw string comparison intentionally differs — use CuredString methods instead
assert_ne!(&*cured, "very funny text with leetspeak");
// Censor a single keyword in-place
cured.censor("funny", '*');
assert_eq!(cured, "very ***** text with leetspeak");
// Censor multiple keywords in-place
cured.censor_multiple(["very", "text"], '-');
assert_eq!(cured, "---- ***** ---- with leetspeak");
// Custom options: retain capitalization, retain Arabic, disable bidi
let options = Options::default()
.retain_capitalization()
.retain_arabic()
.disable_bidi();
let cured2 = decancer::cure("decÁncer", options).unwrap();
assert_eq!(&*cured2, "decAncer");
```
--------------------------------
### Post-Build Copy Command (Windows)
Source: https://github.com/null8626/decancer/blob/main/bindings/native/tests/CMakeLists.txt
On Windows, this command copies the found decancer.dll to the build directory of the test executable after the build is complete. This ensures the DLL is available at runtime.
```cmake
if(WIN32)
add_custom_command(
TARGET decancer_native_test POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${DECANCER_DLL} $
COMMAND_EXPAND_LISTS
)
endif()
```
--------------------------------
### Cure UTF-8 String with Decancer
Source: https://context7.com/null8626/decancer/llms.txt
Demonstrates curing a UTF-8 string using `decancer_cure`. It shows how to retrieve the raw cured string, check for the presence of a substring using `decancer_contains`, find all matches with `decancer_find`, and censor occurrences in-place with `decancer_censor`. Ensure to free the `decancer_cured_t` object after use.
```c
#include
#include
#include
#include
int main(void) {
// UTF-8 input: "vEⓡ𝔂 𝔽𝕌Ňℕy ţ乇𝕏𝓣"
uint8_t input[] = {
0x76, 0xef, 0xbc, 0xa5, 0xe2, 0x93, 0xa1, 0xf0, 0x9d, 0x94, 0x82, 0x20,
0xf0, 0x9d, 0x94, 0xbd, 0xf0, 0x9d, 0x95, 0x8c, 0xc5, 0x87, 0xe2, 0x84,
0x95, 0xef, 0xbd, 0x99, 0x20, 0xc5, 0xa3, 0xe4, 0xb9, 0x87, 0xf0, 0x9d,
0x95, 0x8f, 0xf0, 0x9d, 0x93, 0xa3
};
decancer_error_t error;
decancer_cured_t cured = decancer_cure(
input, sizeof(input), DECANCER_OPTION_DEFAULT, &error
);
if (cured == NULL) {
fprintf(stderr, "error: %.*s\n", (int)error.message_length, error.message);
return 1;
}
// Retrieve raw UTF-8 output
size_t raw_size;
const uint8_t *raw = decancer_cured_raw(cured, NULL, &raw_size);
printf("cured: %.*s\n", (int)raw_size, raw); // "very funny text"
// Contains check
if (decancer_contains(cured, "funny", 5)) {
printf("contains 'funny'\n");
}
// Find all matches
decancer_matcher_t matcher = decancer_find(cured, (const uint8_t*)"funny", 5);
decancer_match_t match;
while (decancer_matcher_next(matcher, &match)) {
printf("match at %zu..%zu\n", match.start, match.end);
}
decancer_matcher_free(matcher);
// Censor in-place
decancer_censor(cured, (const uint8_t*)"funny", 5, '*');
raw = decancer_cured_raw(cured, NULL, &raw_size);
printf("censored: %.*s\n", (int)raw_size, raw); // "very ***** text"
decancer_cured_free(cured);
return 0;
}
```
--------------------------------
### Finding Decancer Library and DLL (Windows)
Source: https://github.com/null8626/decancer/blob/main/bindings/native/tests/CMakeLists.txt
Locates the decancer library file (e.g., libdecancer.so, libdecancer.dylib, decancer.dll.lib) and the decancer.dll on Windows. These are required for linking and deployment.
```cmake
if(WIN32)
find_file(
DECANCER_DLL
NAME "decancer.dll"
HINTS "${CMAKE_CURRENT_SOURCE_DIR}/.." "${CMAKE_CURRENT_SOURCE_DIR}/../target/release" "${CMAKE_CURRENT_SOURCE_DIR}/../target/debug"
REQUIRED
)
endif()
find_library(
DECANCER_LIBRARY
NAMES "decancer.dll.lib" "libdecancer.dylib" "libdecancer.so"
HINTS "${CMAKE_CURRENT_SOURCE_DIR}/.." "${CMAKE_CURRENT_SOURCE_DIR}/../target/release" "${CMAKE_CURRENT_SOURCE_DIR}/../target/debug"
REQUIRED
)
```
--------------------------------
### Add Java Dependency (Gradle)
Source: https://github.com/null8626/decancer/blob/main/README.md
Include the decancer Java library as a dependency in your Gradle build file. Ensure mavenCentral() and jitpack.io() are in your repositories.
```gradle
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'io.github.null8626:decancer:4.0.0'
}
```
--------------------------------
### Import decancer in CommonJS
Source: https://github.com/null8626/decancer/blob/main/bindings/node/README.md
Import the decancer library into your project using CommonJS syntax.
```javascript
const decancer = require('decancer')
```
--------------------------------
### Add Java Dependency (Maven)
Source: https://github.com/null8626/decancer/blob/main/README.md
Include the decancer Java library as a dependency in your Maven pom.xml file. Ensure mavenCentral() and jitpack.io() are in your repositories.
```xml
centralhttps://repo.maven.apache.org/maven2jitpack.iohttps://jitpack.ioio.github.null8626decancer4.0.0
```
--------------------------------
### CuredString Methods (Go)
Source: https://context7.com/null8626/decancer/llms.txt
Describes the methods available on the `CuredString` object returned by the `Cure` function in the Go API.
```APIDOC
## CuredString Methods (Go)
### Description
Methods available on the `CuredString` object returned by `decancer.Cure()`.
### Methods
- **String()**: Returns the cured string.
- **Equals(otherString)**: Checks if the cured string is equal to another string.
- **StartsWith(substring)**: Checks if the cured string starts with a substring.
- **EndsWith(substring)**: Checks if the cured string ends with a substring.
- **Contains(substring)**: Checks if the cured string contains a substring.
- **Find(keyword)**: Returns a slice of `Match` objects (with `Start` and `End` fields) for all occurrences of a keyword.
- **FindMultiple(keywords)**: Merges overlapping matches for multiple keywords, returning a slice of `Match` objects.
- **Censor(keyword, replacement)**: Censos occurrences of a keyword in-place.
- **Replace(keyword, replacement)**: Replaces occurrences of a keyword in-place.
- **Close()**: Must be called to free the underlying C allocation.
### Example
```go
import (
"fmt"
"github.com/null8626/decancer/bindings/go"
)
cured, _ := decancer.Cure("vEⓡ𝔂 𝔽𝕌Ňℕy ţ乇𝕏𝓣", decancer.Default)
defer cured.Close()
cured.Censor("funny", '*')
fmt.Println(cured.String()) // "very ***** text"
```
```
--------------------------------
### Bump version number
Source: https://github.com/null8626/decancer/blob/main/CONTRIBUTING.md
Use this script to update the project's version number. Provide the new version number as an argument.
```bash
node scripts/version.mjs 1.2.3
```
--------------------------------
### CuredString::contains / starts_with / ends_with / PartialEq
Source: https://context7.com/null8626/decancer/llms.txt
Provides fuzzy comparison methods that are case-insensitive and leetspeak-aware by default.
```APIDOC
## CuredString::contains / starts_with / ends_with / PartialEq
### Description
Provides fuzzy comparison methods that are case-insensitive and leetspeak-aware by default. Allows disabling leetspeak matching.
### Method
- `contains(pattern: &str) -> bool`
- `starts_with(pattern: &str) -> bool`
- `ends_with(pattern: &str) -> bool`
- `PartialEq` implementation for fuzzy string comparison.
- `disable_leetspeak(disable: bool)`
- `disable_alphabetical_leetspeak(disable: bool)`
### Parameters
- `pattern` (str): The string pattern to compare against.
- `disable` (bool): Flag to enable or disable leetspeak matching.
### Request Example
```rust
let cured = decancer::cure!("vEⓡ𝔂 𝔽𝕌Ňℕy ţ乇𝕏𝓣").unwrap();
assert!(cured.contains("FuNny")); // case-insensitive
assert!(cured.starts_with("VERY")); // case-insensitive
assert!(cured.ends_with("TEXT")); // case-insensitive
assert_eq!(cured, "very funny text"); // PartialEq fuzzy comparison
// Disable leetspeak matching
let mut cured2 = decancer::cure!("|-|3|_I_0").unwrap();
cured2.disable_leetspeak(true);
cured2.disable_alphabetical_leetspeak(true);
```
### Response
- `contains`, `starts_with`, `ends_with`: Returns `bool` indicating if the pattern matches.
- `PartialEq`: Returns `bool` indicating if the strings are fuzzy-equal.
```
--------------------------------
### Finding Substrings with CuredString.find
Source: https://context7.com/null8626/decancer/llms.txt
Explains how to use the `find` method on a `CuredString` object to locate all occurrences of a substring, returning an array of Match objects.
```javascript
const decancer = require('decancer')
const assert = require('assert')
const cured = decancer('hꡩ𝔏┕⊕𝚑ᅠΎ⫕ᣲ𑀜')
// find: returns array of Match objects with .start, .end, .toString()
const matches = cured.find('hello')
assert.strictEqual(matches.length, 1)
assert.strictEqual(matches[0].start, 0)
assert.strictEqual(matches[0].toString(), 'hello')
```
--------------------------------
### Replacing Substrings in a Cured String
Source: https://context7.com/null8626/decancer/llms.txt
Shows how to use the `replace` method to substitute a substring with another string within a `CuredString` object.
```javascript
// replace / replaceMultiple
const cured2 = decancer('hꡩ𝔏┕⊕𝚑ᅠΎ⫕ᣲ𑀜')
cured2.replace('hello', 'hi')
console.log(cured2.toString()) // 'hi...' (remainder of string)
```
--------------------------------
### Import decancer in ESM
Source: https://github.com/null8626/decancer/blob/main/bindings/node/README.md
Import the decancer library into your project using ECMAScript Module (ESM) syntax.
```javascript
import decancer from 'decancer'
```
--------------------------------
### Runtime Toggling of Leetspeak Decoding
Source: https://context7.com/null8626/decancer/llms.txt
Illustrates how to disable leetspeak decoding at runtime using `disableLeetspeak` and `disableAlphabeticalLeetspeak` methods on a `CuredString` object.
```javascript
// disableLeetspeak runtime toggle
const cured3 = decancer('|-|3|_I_0', { disableLeetspeak: true })
assert(!cured3.equals('hello'))
cured3.disableLeetspeak(false)
cured3.disableAlphabeticalLeetspeak(true)
assert(cured3.equals('helI_o'))
```
--------------------------------
### CuredString Methods (JavaScript)
Source: https://context7.com/null8626/decancer/llms.txt
Describes the methods available on the `CuredString` object returned by the `decancer()` function in JavaScript.
```APIDOC
## CuredString Methods
### Description
Methods available on the `CuredString` object returned by `decancer()`.
### Methods
- **find(keyword)**: Returns an array of Match objects with `.start`, `.end`, and `.toString()`.
- **findMultiple(keywords)**: Merges overlapping matches for multiple keywords.
- **replace(keyword, replacement)**: Replaces occurrences of a keyword in-place.
- **replaceMultiple(keywords, replacement)**: Replaces multiple keywords in-place.
- **censor(keyword, replacement)**: Censos occurrences of a keyword in-place.
- **censorMultiple(keywords, replacement)**: Censos multiple keywords in-place.
- **equals(otherString)**: Checks if the cured string is equal to another string.
- **contains(substring)**: Checks if the cured string contains a substring.
- **startsWith(substring)**: Checks if the cured string starts with a substring.
- **endsWith(substring)**: Checks if the cured string ends with a substring.
- **toString()**: Returns the cured string.
- **disableLeetspeak(enable)**: Toggles leetspeak disabling at runtime.
- **disableAlphabeticalLeetspeak(enable)**: Toggles alphabetical leetspeak disabling at runtime.
### Example
```javascript
const decancer = require('decancer');
const cured = decancer('hꡩ𝔏┕⊕𝚑ᅠΎ⫕ᣲ𑀜');
const matches = cured.find('hello');
console.log(matches[0].toString()); // 'hello'
cured.censor('hello', '*');
console.log(cured.toString()); // '***...'`
```
```
--------------------------------
### Cure(input, options) — Cure a string (Go)
Source: https://context7.com/null8626/decancer/llms.txt
The primary function in the Go API to clean a string. It takes the input string and an options bitfield, returning a `CuredString` object or an error.
```APIDOC
## Cure(input, options)
### Description
Cures a given string using specified options in Go. Returns a `CuredString` object and an error if any.
### Parameters
- **input** (string) - The string to be cured.
- **options** (uint32) - A bitfield representing the curing options (e.g., `decancer.Default`, `decancer.RetainCapitalization`).
### Returns
- `*decancer.CuredString` - A pointer to the CuredString object.
- `error` - An error if the curing process fails.
### Example
```go
import (
"fmt"
"github.com/null8626/decancer/bindings/go"
)
cured, err := decancer.Cure("vEⓡ𝔂 𝔽𝕌Ňℕy ţ乇𝕏𝓣", decancer.Default)
if err != nil {
fmt.Println("error:", err)
}
defer cured.Close()
fmt.Println(cured.String())
// => very funny text
```
```
--------------------------------
### Initialize Decancerer WASM and Cure Text
Source: https://github.com/null8626/decancer/blob/main/bindings/wasm/example.html
Imports the Decancerer WASM module and sets up a function to clean text from a textarea. Ensure the WASM module is correctly imported before calling this function.
```javascript
import init from 'https://null8626.github.io/decancer/bindings/wasm/bin/decancer.min.js'
const decancer = await init()
window.cure = function () {
const textarea = document.querySelector('textarea')
if (!textarea.value.length) {
return alert("There's no text!!!")
}
textarea.value = decancer(textarea.value).toString()
}
```
--------------------------------
### Update Unicode cache
Source: https://github.com/null8626/decancer/blob/main/CONTRIBUTING.md
This script should be run when a new Unicode version is released to update the project's internal cache. This ensures compatibility with the latest Unicode standards.
```bash
node scripts/update_unicode.mjs
```
--------------------------------
### Cure UTF-8 Text with Decancer
Source: https://github.com/null8626/decancer/blob/main/bindings/native/README.md
Demonstrates how to cure a UTF-8 encoded byte array using decancer_cure. Includes assertion for checking if the cured text contains a specific substring.
```c
#include
#include
#include
#include
#define decancer_assert(expr, notes) \
if (!(expr)) { \
fprintf(stderr, "assertion failure at " notes "\n"); \
ret = 1; \
goto END; \
}
int main() {
int ret = 0;
// UTF-8 bytes for "vEⓡ𝔂 𝔽𝕌Ňℕy ţ乇𝕏𝓣"
uint8_t input[] = {0x76, 0xef, 0xbc, 0xa5, 0xe2, 0x93, 0xa1, 0xf0, 0x9d, 0x94, 0x82, 0x20, 0xf0, 0x9d,
0x94, 0xbd, 0xf0, 0x9d, 0x95, 0x8c, 0xc5, 0x87, 0xe2, 0x84, 0x95, 0xef, 0xbd, 0x99,
0x20, 0xc5, 0xa3, 0xe4, 0xb9, 0x87, 0xf0, 0x9d, 0x95, 0x8f, 0xf0, 0x9d, 0x93, 0xa3};
decancer_error_t error;
decancer_cured_t cured = decancer_cure(input, sizeof(input), DECANCER_OPTION_DEFAULT, &error);
if (cured == NULL) {
fprintf(stderr, "curing error: %.*s\n", (int)error.message_length, error.message);
return 1;
}
decancer_assert(decancer_contains(cured, "funny", 5), "decancer_contains");
END:
decancer_cured_free(cured);
return ret;
}
```