🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more →
Socket
Book a DemoInstallSign in
Socket

me.zolotov.oniguruma:oniguruma-jni

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

me.zolotov.oniguruma:oniguruma-jni

A JNI wrapper for the Oniguruma regular expression library, with Rust implementation using the onig crate. This library is primarily designed to support syntax highlighting in IntelliJ-based IDEs through the textmate-core library.

Source
mavenMaven
Version
1.0.2
Version published
Maintainers
1
Source

Oniguruma JNI

Maven central version GitHub Actions Workflow Status GitHub License

A JNI wrapper for the Oniguruma regular expression library, with Rust implementation using the onig crate. This library is primarily designed to support syntax highlighting in IntelliJ-based IDEs through the textmate-core library.

Overview

This project provides Java Native Interface (JNI) bindings for TextMate grammar pattern matching, implemented in Rust using the onig crate which provides the native bindings to the Oniguruma regular expression library.

Installation

Add the following dependency to your project:

dependencies {
    implementation("me.zolotov.oniguruma:oniguruma-jni:$version")
}

Usage

Basic Setup

// Load the library from bundled resources
// Note: This method has performance overhead during instantiation (unpacking a native part from jar)
// and JVM shutdown (cleanup hook to remove the unpacked file)
val oniguruma = Oniguruma.createFromResources()

// Or load from a specific file path (preferred for better performance)
val oniguruma = Oniguruma.createFromFile(Path.of("/path/to/library"))

Pattern Matching

val oniguruma = Oniguruma.createFromResources()

// Create pattern and string handles
val pattern = "pattern".toByteArray()
val text = "text to match".toByteArray()

val textPtr = oniguruma.createString(text)
try {
    val regexPtr = oniguruma.createRegex(pattern)
    try {
        val result = oniguruma.match(
            regexPtr = regexPtr,
            textPtr = textPtr,
            byteOffset = 0,
            matchBeginPosition = true,
            matchBeginString = false
        )

        // Process results
        result?.let {
            // Match found, process the integer array of positions
            it.asSequence()?.windowed(size = 2, step = 2, partialWindows = false) { (startByteOffset, endByteOffset) ->

            }
        }
    } finally {
        // Clean up native regex
        oniguruma.freeRegex(regexPtr)
    }
} finally {
    // Clean up native string
    oniguruma.freeString(textPtr)
}

Building from Source

  • Clone the repository
  • Ensure you have the following prerequisites:
    • JDK 8 or later
    • Rust toolchain
  • Build the project using Gradle:
    ./gradlew build
    

Contributing

Contributions are welcome! Please feel free to submit pull requests.

Acknowledgments

  • Oniguruma library developers
  • onig-rs crate maintainers

Note

This library is primarily intended for use with the textmate-core library in IntelliJ-based IDEs. While it can be used independently, the API is designed with this specific use case in mind.

FAQs

Package last updated on 29 Jul 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts