[gnumeric] Implement FINDB



commit e23ca2d8f12148c13d28adbe88bd9dbe7c11e563
Author: Andreas J. Guelzow <aguelzow pyrshep ca>
Date:   Mon Aug 17 23:10:42 2009 -0600

    Implement FINDB
    
    2009-08-17 Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* functions.c (help_findb): new
    	(gnumeric_findb): new
    	(string_functions): add FINDB
    	* plugin.xml.in: add FINDB
    
    2009-08-17 Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* openoffice-write.c (odf_expr_func_handler): we now have a
    	  FINDB and AVERAGEIF
    	* openoffice-read.c (oo_func_map_in): we now have a FINDB and
    	  AVERAGEIF

 plugins/fn-string/ChangeLog           |    7 +++++
 plugins/fn-string/functions.c         |   46 +++++++++++++++++++++++++++++++++
 plugins/fn-string/plugin.xml.in       |    1 +
 plugins/openoffice/ChangeLog          |    7 +++++
 plugins/openoffice/openoffice-read.c  |    4 +--
 plugins/openoffice/openoffice-write.c |    3 +-
 6 files changed, 64 insertions(+), 4 deletions(-)
---
diff --git a/plugins/fn-string/ChangeLog b/plugins/fn-string/ChangeLog
index ae1afda..74fe719 100644
--- a/plugins/fn-string/ChangeLog
+++ b/plugins/fn-string/ChangeLog
@@ -1,3 +1,10 @@
+2009-08-17 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* functions.c (help_findb): new
+	(gnumeric_findb): new
+	(string_functions): add FINDB
+	* plugin.xml.in: add FINDB
+	
 2009-08-15  Morten Welinder <terra gnome org>
 
 	* Release 1.9.10
diff --git a/plugins/fn-string/functions.c b/plugins/fn-string/functions.c
index d543425..5a46395 100644
--- a/plugins/fn-string/functions.c
+++ b/plugins/fn-string/functions.c
@@ -415,6 +415,49 @@ gnumeric_midb (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
 
 /***************************************************************************/
 
+static GnmFuncHelp const help_findb[] = {
+        { GNM_FUNC_HELP_NAME, F_("FINDB:first byte position of @{string1} in @{string2} following byte position @{start}")},
+        { GNM_FUNC_HELP_ARG, F_("string1:search string")},
+        { GNM_FUNC_HELP_ARG, F_("string2:search field")},
+        { GNM_FUNC_HELP_ARG, F_("start:starting byte position, defaults to 1")},
+        { GNM_FUNC_HELP_NOTE, F_("This search is case-sensitive.")},
+	{ GNM_FUNC_HELP_EXCEL, F_("While this function is syntactically Excel compatible, "
+				  "the differences in the underlying text encoding will usually yield different results.")},
+	{ GNM_FUNC_HELP_ODF, F_("While this function is OpenFormula compatible, most of its behavior is, at this time, implementation specific.")},
+	{ GNM_FUNC_HELP_EXAMPLES, "=FINDB(\"v\",\"L\xc3\xa9vy\")" },
+	{ GNM_FUNC_HELP_EXAMPLES, "=FINDB(\"v\",\"L\xc3\xa9vy\",3)" },
+	{ GNM_FUNC_HELP_EXAMPLES, "=FINDB(\"v\",\"L\xc3\xa9vy\",5)" },
+	{ GNM_FUNC_HELP_SEEALSO, "FIND,LEFTB,RIGHTB,LENB,LEFT,MID,RIGHT,LEN"},
+        { GNM_FUNC_HELP_END}
+};
+
+static GnmValue *
+gnumeric_findb (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
+{
+	char const *needle   = value_peek_string (argv[0]);
+	char const *haystack = value_peek_string (argv[1]);
+	gnm_float count      = argv[2] ? value_get_as_float (argv[2]) : 1.0;
+	size_t haystacksize = strlen (haystack);
+	size_t icount;
+	char const *p;
+
+
+	if (count < 1 || count >= haystacksize + 1)
+		return value_new_error_VALUE (ei->pos);
+
+	icount = (size_t) count;
+	p = (icount == 1) ? haystack : g_utf8_find_next_char (haystack + (icount - 2) , NULL);
+
+	p = g_strstr_len (p, strlen (p), needle);
+	if (p)
+		return value_new_int
+			((p - haystack) + 1);
+	else
+		return value_new_error_VALUE (ei->pos);
+}
+
+/***************************************************************************/
+
 static GnmFuncHelp const help_right[] = {
 	{ GNM_FUNC_HELP_NAME, F_("RIGHT:the last @{num_chars} characters of the string @{s}")},
 	{ GNM_FUNC_HELP_ARG, F_("s:the string")},   
@@ -1433,6 +1476,9 @@ GnmFuncDescriptor const string_functions[] = {
         { "find",       "SS|f",           help_find,
 	  gnumeric_find, NULL, NULL, NULL, NULL,
 	  GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
+        { "findb",       "SS|f",           help_findb,
+	  gnumeric_findb, NULL, NULL, NULL, NULL,
+	  GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
         { "fixed",      "f|fb",        help_fixed,
 	  gnumeric_fixed, NULL, NULL, NULL, NULL,
 	  GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
diff --git a/plugins/fn-string/plugin.xml.in b/plugins/fn-string/plugin.xml.in
index de64a5d..5b42e79 100644
--- a/plugins/fn-string/plugin.xml.in
+++ b/plugins/fn-string/plugin.xml.in
@@ -19,6 +19,7 @@
 				<function name="dollar"/>
 				<function name="exact"/>
 				<function name="find"/>
+				<function name="findb"/>
 				<function name="fixed"/>
 				<function name="jis"/>
 				<function name="left"/>
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index 03a3679..1501b26 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,3 +1,10 @@
+2009-08-17 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* openoffice-write.c (odf_expr_func_handler): we now have a
+	  FINDB and AVERAGEIF
+	* openoffice-read.c (oo_func_map_in): we now have a FINDB and
+	  AVERAGEIF
+
 2009-08-15  Morten Welinder <terra gnome org>
 
 	* Release 1.9.10
diff --git a/plugins/openoffice/openoffice-read.c b/plugins/openoffice/openoffice-read.c
index ff92ad7..0b7a8ef 100644
--- a/plugins/openoffice/openoffice-read.c
+++ b/plugins/openoffice/openoffice-read.c
@@ -4571,7 +4571,6 @@ oo_func_map_in (GnmConventions const *convs, Workbook *scope,
 		{ "COUNTIFS","ODF.COUNTIFS" },
 		{ "DAYS","ODF.DAYS" },
 		{ "DDE","ODF.DDE" },
-		{ "FINDB","ODF.FINDB" },
 		{ "GAMMA","ODF.GAMMA" },
 		{ "GAUSS","ODF.GAUSS" },
 		{ "IFNA","ODF.IFNA" },
@@ -4607,8 +4606,6 @@ oo_func_map_in (GnmConventions const *convs, Workbook *scope,
 		{ "USDOLLAR","DOLLAR" },
 
 /* { "ADDRESS","ADDRESS" },       also  see handler */
-
-
 /* { "ABS","ABS" }, */
 /* { "ACCRINT","ACCRINT" }, */
 /* { "ACCRINTM","ACCRINTM" }, */
@@ -4630,6 +4627,7 @@ oo_func_map_in (GnmConventions const *convs, Workbook *scope,
 /* { "AVEDEV","AVEDEV" }, */
 /* { "AVERAGE","AVERAGE" }, */
 /* { "AVERAGEA","AVERAGEA" }, */
+/* { "AVERAGEIF","AVERAGEIF" }, */
 /* { "AVERAGEIFS","AVERAGEIFS" }, */
 /* { "B","B" }, */
 /* { "BASE","BASE" }, */
diff --git a/plugins/openoffice/openoffice-write.c b/plugins/openoffice/openoffice-write.c
index f700aab..fed68e2 100644
--- a/plugins/openoffice/openoffice-write.c
+++ b/plugins/openoffice/openoffice-write.c
@@ -1585,6 +1585,7 @@ odf_expr_func_handler (GnmConventionsOut *out, GnmExprFunction const *func)
 		{ "AVEDEV","AVEDEV" },
 		{ "AVERAGE","AVERAGE" },
 		{ "AVERAGEA","AVERAGEA" },
+		{ "AVERAGEIF","AVERAGEIF" },
 		/* { "ODF.AVERAGEIFS","AVERAGEIFS" },  not implemented */
 		/* { "ODF.B","B" },  not implemented */
 		{ "BASE","BASE" },
@@ -1690,7 +1691,7 @@ odf_expr_func_handler (GnmConventionsOut *out, GnmExprFunction const *func)
 		{ "FACTDOUBLE","FACTDOUBLE" },
 		{ "FALSE","FALSE" },
 		{ "FIND","FIND" },
-		/* { "FINDB","FINDB" },  not implemented */
+		{ "FINDB","FINDB" },
 		{ "FISHER","FISHER" },
 		{ "FISHERINV","FISHERINV" },
 		{ "FIXED","FIXED" },



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]