[CDRIVER-20] Not-null-terminated string support Created: 27/Jul/10  Updated: 19/Oct/16  Resolved: 08/Apr/11

Status: Closed
Project: C Driver
Component/s: None
Affects Version/s: None
Fix Version/s: 0.2

Type: Improvement Priority: Major - P3
Reporter: Stanis?aw Pitucha Assignee: Kyle Banker
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

I'd like to propose a new set of functions that can deal with not null terminated strings. It would really help in situations where names are part of a longer string. (just like there are strcpy and strncpy)

For example for:
bson_buffer * bson_append_string( bson_buffer * b , const char * name , const char * str );
there could be:
bson_buffer * bson_append_string_n( bson_buffer * b , const char * name , const char * str , unsigned len );

Same idea affects other types (symbol, code, regex, ...)



 Comments   
Comment by auto [ 14/Apr/11 ]

Author:

{u'login': u'banker', u'name': u'Kyle Banker', u'email': u'kylebanker@gmail.com'}

Message: minor: credits for CDRIVER-20
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/a0a4a5d791306d1dbec297d987d7581e5158f179

Comment by auto [ 14/Apr/11 ]

Author:

{u'login': u'algernon', u'name': u'Gergely Nagy', u'email': u'algernon@balabit.hu'}

Message: CDRIVER-20: bson _append_n functions.

Added bson_append_string_n, bson_append_symbol_n, bson_append_code_n
and bson_append_code_w_scope_n, which do the same as their _n-less
counterparts, except that they take the value of the object to insert
up to a given length, instead of 'till the end of the C string.
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/fc613cf459bbb69e874fe4899cdaad046543d092

Comment by auto [ 08/Apr/11 ]

Author:

{u'login': u'banker', u'name': u'Kyle Banker', u'email': u'kylebanker@gmail.com'}

Message: minor: credits for CDRIVER-20
Branch: dev
https://github.com/mongodb/mongo-c-driver/commit/a0a4a5d791306d1dbec297d987d7581e5158f179

Comment by auto [ 08/Apr/11 ]

Author:

{u'login': u'algernon', u'name': u'Gergely Nagy', u'email': u'algernon@balabit.hu'}

Message: CDRIVER-20: bson _append_n functions.

Added bson_append_string_n, bson_append_symbol_n, bson_append_code_n
and bson_append_code_w_scope_n, which do the same as their _n-less
counterparts, except that they take the value of the object to insert
up to a given length, instead of 'till the end of the C string.
Branch: dev
https://github.com/mongodb/mongo-c-driver/commit/fc613cf459bbb69e874fe4899cdaad046543d092

Comment by Gergely Nagy [ 07/Jan/11 ]

I added the neccessary functions (see https://github.com/algernon/mongo-c-driver/tree/j/CDRIVER-20 ), and sent a pull request aswell.

string, code, symbol and code_w_scope received an _n variant, those four made sense to me. Tests were added to the test_all_types test case.

Comment by Gergely Nagy [ 07/Jan/11 ]

I would like to second this request. Just today, I ran into an issue where I had a string buffer, of which I wanted to insert the first N bytes into a bson buffer, but there was no ready made function for that. I will have a patch ready, that implements _n for the _append functions where it makes sense.

GitHub pull request will follow soon after.

For the record, my situation is as follows: I take a string, and find patterns in it, whenever a pattern is found, I record the starting position within the string, and the length. Now, I want to put the matches into mongodb. Either I copy the values, which I really do not want to, or I add the _append_n functions. The latter solution is much more preferable, in my opinion, and there's plenty of good reasons to want them anyway.

Comment by Stanis?aw Pitucha [ 27/Jul/10 ]

Actually, there could also be a version for non-terminated, known-size `name` for every append function...

Generated at Wed Feb 07 21:08:13 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.