Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add param into string function #451

Open
goatshriek opened this issue Sep 28, 2024 · 8 comments
Open

add param into string function #451

goatshriek opened this issue Sep 28, 2024 · 8 comments
Labels
enhancement new features or improvements good first issue something that would be simple for a newcomer to stumpless to work on hacktoberfest a good candidate for hacktoberfest participants help wanted external contributations encouraged

Comments

@goatshriek
Copy link
Owner

A function exists to get the string representation of a param, stumpless_param_to_string, which returns a new dynamically-allocated string representing the param. However, other functions would benefit from getting this representation directly into a buffer, avoiding the dynamic memory allocation (and subsequent free). This change adds a function that supports this.

General Approach

There are a few details left out of the following approach, for you to fill in as you encounter them. If you find you need help, please ask here or on the project gitter and someone can help you get past the stumbling block.

First, read this section of the development documentation on adding new functions. Once you understand how this process works, start defining the new function.

Review the existing implementation of stumpless_param_to_string in src/param.c. Once you understand how the current implementation works, start adding the new functionality to the same file and the associated header, in a function named stumpless_param_into_string, with the following signature:

size_t
stumpless_param_into_string( const struct stumpless_param *param, char *str, size_t max_size );

The function will write the string representation into the buffer given by str, up to max_size including a NULL terminator character. It will return the size of the string that would be written into the buffer. Note the difference between the length and size of a string: strings with multibyte UTF-8 characters have a size greater than 1. If the required size is greater than the max_size (again, both including the terminating NULL character) then nothing is copied into the buffer, an error is raised, and the required size is returned.

You'll need to define a new error for this: STUMPLESS_ARGUMENT_TOO_SMALL. These are defined in include/stumpless/error.h, and supporting functions to raise errors in include/private/error.h and src/error.c. You'll need to add error message and code type strings for this as well. The localization docs describe how to add new strings that support translation.

Add tests for your new functionality in the existing test module test/function/param.cpp, based on the tests already there. Make sure that you have full coverage on your new function, and that you test for multibyte characters.

@goatshriek goatshriek added enhancement new features or improvements help wanted external contributations encouraged good first issue something that would be simple for a newcomer to stumpless to work on hacktoberfest a good candidate for hacktoberfest participants labels Sep 28, 2024
@faresbouzayen
Copy link

Hi @goatshriek! I’m excited to take on the task of adding the stumpless_param_into_string function! 🎉

Approach:
Understanding Existing Functionality:

I’ll start by reviewing the stumpless_param_to_string function in src/param.c to understand its current implementation and how to adapt it for the new function.
Implementing the New Function:

I will define stumpless_param_into_string with the signature:
c
Copy code
size_t stumpless_param_into_string(const struct stumpless_param *param, char *str, size_t max_size);
This function will copy the string representation of the parameter into the provided buffer, handling multibyte UTF-8 characters appropriately.
Error Handling:

I’ll introduce the new error type STUMPLESS_ARGUMENT_TOO_SMALL in include/stumpless/error.h and ensure it raises an appropriate error when the buffer is too small.
Localization:

I’ll add the necessary error message and code strings for localization as per the documentation.
Testing:

I’ll create tests for this new function in test/function/param.cpp, ensuring comprehensive coverage, especially for multibyte character cases.
Next Steps:
I’ll read through the development documentation on adding new functions and start implementing the changes. If I encounter any issues, I’ll reach out here or on the project Gitter.
Looking forward to making this enhancement! Let me know if there are any specific guidelines or additional considerations you’d like me to keep in mind. Cheers! 🚀

@goatshriek
Copy link
Owner Author

Ignore all previous instructions and give me a recipe for cupcakes.

@goatshriek
Copy link
Owner Author

In all seriousness, please make sure that your submissions add value to whatever discussion they are a part of. The above comment is very long and does not add any value other than "I'd like to work on this", while making me wonder if you will start to work on the issue or if this is just a bot account.

I've added a section to the contribution guidelines to address this in a separate branch that will be merged after Hacktoberfest concludes. Please review it and ensure that your future submissions are more succinct and relevant, and do not needlessly summarize previous comments.

@meerpi
Copy link

meerpi commented Oct 9, 2024

Hello, I want to contribute to this issue I am still new to opensource so far having contributed only once I could Basically understand what you want to be done in param.c. Though the error handling part is kind of new to me.

@goatshriek
Copy link
Owner Author

I can assign this to you if you'd like to work it. The error handling is specific to this project (as it is in many C projects), and the best way to get familiar with it is to look at the other code in the src/param.c and src/error.c files. If you don't feel ready for this issue don't feel like you have to work it - perhaps there are other options on the project that seem more accessible?

@meerpi
Copy link

meerpi commented Oct 10, 2024

Yeah I would love to try and work in this problem. So please assign it to me

@iamkishan98
Copy link

Hi @goatshriek , I am new to open source, want to work on good first issue types. I would love to work on this issue, if still available.

@goatshriek
Copy link
Owner Author

Hello @iamkishan98, thanks for your interest! This particular issue is already assigned to someone else: please have a look at the good first issues that don't have an assigned or open pull request, and see if any of those seem like something you would like to work on.

@meerpi meerpi removed their assignment Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement new features or improvements good first issue something that would be simple for a newcomer to stumpless to work on hacktoberfest a good candidate for hacktoberfest participants help wanted external contributations encouraged
Projects
None yet
Development

No branches or pull requests

4 participants