Skip to content

rainerscript: add split() function#6384

Merged
rgerhards merged 1 commit intorsyslog:mainfrom
20syldev:split
Dec 26, 2025
Merged

rainerscript: add split() function#6384
rgerhards merged 1 commit intorsyslog:mainfrom
20syldev:split

Conversation

@20syldev
Copy link
Copy Markdown
Contributor

Summary

Users need to parse delimited strings (CSV, tags, paths) into arrays for iteration or JSON output without external processing.

Notes

  • Tests included: rscript_split.sh and rscript_split-vg.sh
  • Documentation added: doc/source/rainerscript/functions/rs-split.rst

Impact: New RainerScript function available to all users.

  • Before: No native way to split strings into arrays in RainerScript.
  • After: split(string, separator) returns a JSON array of substrings.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @20syldev, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a highly anticipated split() function to RainerScript, significantly enhancing its string manipulation capabilities. The new function allows users to effortlessly break down delimited strings into JSON arrays, providing a native solution for parsing structured data such as CSV, tag lists, or file paths. This addition streamlines workflows by enabling direct processing of such data within RainerScript, improving efficiency and reducing reliance on external tools.

Highlights

  • New split() function: Introduces a new split(string, separator) function to RainerScript, allowing users to parse delimited strings into JSON arrays.
  • String to Array Conversion: This function addresses the need to convert delimited strings (like CSV, tags, or paths) into iterable JSON arrays directly within RainerScript, eliminating the need for external processing.
  • Comprehensive Testing and Documentation: The new functionality is accompanied by dedicated test cases (rscript_split.sh, rscript_split-vg.sh) and comprehensive documentation (doc/source/rainerscript/functions/rs-split.rst) detailing its purpose, syntax, parameters, return value, and examples.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new split() function to RainerScript, which is a useful addition for string manipulation. The implementation in grammar/rainerscript.c is generally sound and covers several edge cases. The new documentation and tests are also appreciated.

I have a couple of suggestions to improve the error handling within the doFunct_split function. These changes will make the function more robust, especially in out-of-memory scenarios, by ensuring it fails cleanly instead of returning partial results.

@rgerhards rgerhards self-assigned this Dec 24, 2025
@rgerhards rgerhards added this to the v8.2602 milestone Dec 24, 2025
@rgerhards
Copy link
Copy Markdown
Member

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a useful split() function to RainerScript for parsing delimited strings. The implementation is well-structured, including proper error handling and memory management. The new function is also documented and accompanied by tests. My review focuses on improving the function's correctness for edge cases and enhancing test coverage to ensure its robustness.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new split() function to RainerScript, which is a great addition for parsing delimited strings. The implementation is solid, and the accompanying documentation and tests are comprehensive.

I have two main suggestions:

  1. In grammar/rainerscript.c, the error handling for NULL inputs could be improved to be more consistent. Currently, it returns an empty array, which might hide an underlying memory allocation failure. Returning NULL would be a clearer way to signal an error.
  2. In the new documentation file doc/source/rainerscript/functions/rs-split.rst, a newline is missing at the end of the file. It's a minor point but good practice to add one.

Overall, this is a well-executed feature addition.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new split() function to RainerScript, which is a useful addition for parsing delimited strings. The implementation is robust and includes good test coverage for various edge cases. I have one suggestion regarding the error handling and structure of the doFunct_split function to improve its maintainability and clarity. Overall, this is a solid contribution.

Copy link
Copy Markdown
Member

@rgerhards rgerhards left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • code style needs to be fixed, can be done by running develtools/format-code.sh - if that does not work due to dependencies, let me know and I will do and ammend to your PR
  • the doc should contain a complete example also showing how to process after the split (for a sample use case)

Users need to parse delimited strings (CSV, tags, paths) into arrays
for iteration or JSON output without external processing.

Impact: New RainerScript function available to all users.

Before: No native way to split strings into arrays in RainerScript.
After: split(string, separator) returns a JSON array of substrings.

Technical overview:
Implements doFunct_split() in grammar/rainerscript.c
Registers "split" in scriptFunct table with 2 required args
Adds CNFFUNC_SPLIT enum in rainerscript.h
Uses unified strstr-based iteration for all separator lengths
Handles edge cases: empty input, leading/trailing/consecutive delimiters
Includes error handling for json-c memory allocation failures
Returns empty JSON array on null/empty input or separator
Includes documentation (rs-split.rst) and test scripts
@20syldev
Copy link
Copy Markdown
Contributor Author

20syldev commented Dec 24, 2025

  • code style needs to be fixed, can be done by running develtools/format-code.sh - if that does not work due to dependencies, let me know and I will do and ammend to your PR
  • the doc should contain a complete example also showing how to process after the split (for a sample use case)

My bad, I did the code formatting, but I forgot to redo it just before pushing.
I also added the missing doc

@20syldev 20syldev requested a review from rgerhards December 24, 2025 13:05
@rgerhards rgerhards merged commit 1b9d88c into rsyslog:main Dec 26, 2025
47 checks passed
@20syldev 20syldev deleted the split branch December 26, 2025 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants