Summary: | ASTERISK-16431: [patch] Add FIELDNUM() function, returns position of a field in a list | ||
Reporter: | Gareth Palmer (gareth) | Labels: | |
Date Opened: | 2010-07-26 00:08:54 | Date Closed: | 2010-08-03 15:29:50 |
Priority: | Major | Regression? | No |
Status: | Closed/Complete | Components: | Functions/NewFeature |
Versions: | Frequency of Occurrence | ||
Related Issues: | |||
Environment: | Attachments: | ( 0) svn-276613.diff ( 1) svn-279754.diff | |
Description: | FIELDNUM() returns the position of a field in a character delimited list, ie: Set(LIST=apples/oranges/bananas/grapes) ${FIELDNUM(LIST,/,oranges)} => Returns '2' ${FIELDNUM(LIST,/,bananas)} => Returns '3' ${FIELDNUM(LIST,/,chicken)} => Returns '0' ${FIELDNUM(LIST,#,bananas)} => Returns '0' (Note: wrong delimiter) | ||
Comments: | By: jmls (jmls) 2010-07-26 01:59:52 Nice. A lot of my data returned from the db or realtime etc is comma-seperated. How would I specify , as the delimiter ? Thanks. By: Gareth Palmer (gareth) 2010-07-26 06:14:44 @jmls: you can specify the delimiter in either octal or hexadecimal so ${FIELDNUM(DATA,\x2c,WORD)} or ${FIELDNUM(DATA,\054,WORD)} should work. ${FIELDQTY()} and ${CUT()} use the same syntax for parsing the delimiter. By: Paul Belanger (pabelanger) 2010-07-26 08:03:10 I'd also like to see a test for the TEST_FRAMEWORK included. :) By: Leif Madsen (lmadsen) 2010-07-26 10:54:42 Could you also do this? ${FIELDNUM(DATA,\,,WORD)} By: Leif Madsen (lmadsen) 2010-07-26 10:55:59 Thanks for updating the CHANGES file and adding good documentation to xmldocs! By: Leif Madsen (lmadsen) 2010-07-26 10:58:43 I'm going to mark this as scheduled for 1.8.0. This would mean we need to get some people to test it, and a code review done over the next week or so. By: Gareth Palmer (gareth) 2010-07-26 21:57:01 Oops, first patch has a bug. It didn't actually register the function, fixed. @pabelanger: Test framework included now. @lmadsen: Yes, you can use \, as well. By: Tilghman Lesher (tilghman) 2010-07-26 23:42:56 Please add your patch to https://reviewboard.asterisk.org/. Use your same username and password as on issues to login. I'd like to review this patch line by line. One thing that needs to be done is to check the return value of ast_get_encoded_char, to ensure that the input for the field is valid. A second thing to do is to use the read2 API for your custom function instead of the original; there is an additional efficiency benefit with returning a dynamic string buffer, as Asterisk does not need to allocate a large buffer for a small numeric result. Even if you didn't do this, specifying read_max as 12 (maximum size for a positive integer) additionally assists in this efficiency. By: Gareth Palmer (gareth) 2010-07-27 21:15:10 @tilghman: I've added support for the read2 API and put it on reviewboard. By: Digium Subversion (svnbot) 2010-08-03 15:25:08 Repository: asterisk Revision: 280809 U branches/1.8/CHANGES U branches/1.8/funcs/func_strings.c ------------------------------------------------------------------------ r280809 | tilghman | 2010-08-03 15:25:08 -0500 (Tue, 03 Aug 2010) | 12 lines Sneak FIELDNUM() into 1.8. Returns a 1-based index into a list of a specified item. Matches up with FIELDQTY() and CUT(). (closes issue ASTERISK-16431) Reported by: gareth Patches: svn-279754.diff uploaded by gareth (license 208) Tested by: gareth, tilghman Review: https://reviewboard.asterisk.org/r/810/ ------------------------------------------------------------------------ http://svn.digium.com/view/asterisk?view=rev&revision=280809 By: Digium Subversion (svnbot) 2010-08-03 15:29:50 Repository: asterisk Revision: 280810 _U trunk/ U trunk/CHANGES U trunk/funcs/func_strings.c ------------------------------------------------------------------------ r280810 | tilghman | 2010-08-03 15:29:49 -0500 (Tue, 03 Aug 2010) | 19 lines Merged revisions 280809 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ........ r280809 | tilghman | 2010-08-03 15:25:10 -0500 (Tue, 03 Aug 2010) | 12 lines Sneak FIELDNUM() into 1.8. Returns a 1-based index into a list of a specified item. Matches up with FIELDQTY() and CUT(). (closes issue ASTERISK-16431) Reported by: gareth Patches: svn-279754.diff uploaded by gareth (license 208) Tested by: gareth, tilghman Review: https://reviewboard.asterisk.org/r/810/ ........ ------------------------------------------------------------------------ http://svn.digium.com/view/asterisk?view=rev&revision=280810 |