--- /dev/null
+/* ====================================================================\r
+ Licensed to the Apache Software Foundation (ASF) under one or more\r
+ contributor license agreements. See the NOTICE file distributed with\r
+ this work for additional information regarding copyright ownership.\r
+ The ASF licenses this file to You under the Apache License, Version 2.0\r
+ (the "License"); you may not use this file except in compliance with\r
+ the License. You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+==================================================================== */\r
+\r
+package org.apache.poi.ss.formula.functions;\r
+\r
+import org.apache.poi.ss.formula.OperationEvaluationContext;\r
+import org.apache.poi.ss.formula.eval.*;\r
+\r
+import java.math.BigDecimal;\r
+\r
+/**\r
+ * Implementation for Excel REPT () function.<p/>\r
+ * <p/>\r
+ * <b>Syntax</b>:<br/> <b>REPT </b>(<b>text</b>,<b>number_times</b> )<br/>\r
+ * <p/>\r
+ * Repeats text a given number of times. Use REPT to fill a cell with a number of instances of a text string.\r
+ *\r
+ * text : text The text that you want to repeat.\r
+ * number_times: A positive number specifying the number of times to repeat text.\r
+ *\r
+ * If number_times is 0 (zero), REPT returns "" (empty text).\r
+ * If this argument contains a decimal value, this function ignores the numbers to the right side of the decimal point.\r
+ *\r
+ * The result of the REPT function cannot be longer than 32,767 characters, or REPT returns #VALUE!.\r
+ *\r
+ * @author cedric dot walter @ gmail dot com\r
+ */\r
+public class Rept extends Fixed2ArgFunction {\r
+\r
+\r
+ @Override\r
+ public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval text, ValueEval number_times) {\r
+\r
+ ValueEval veText1;\r
+ try {\r
+ veText1 = OperandResolver.getSingleValue(text, srcRowIndex, srcColumnIndex);\r
+ } catch (EvaluationException e) {\r
+ return e.getErrorEval();\r
+ }\r
+ String strText1 = OperandResolver.coerceValueToString(veText1);\r
+ double numberOfTime = 0;\r
+ try {\r
+ numberOfTime = OperandResolver.coerceValueToDouble(number_times);\r
+ } catch (EvaluationException e) {\r
+ return ErrorEval.VALUE_INVALID;\r
+ }\r
+\r
+ int numberOfTimeInt = new Double(numberOfTime).intValue();\r
+ StringBuffer strb = new StringBuffer(strText1.length() * numberOfTimeInt);\r
+ for(int i = 0; i < numberOfTimeInt; i++) {\r
+ strb.append(strText1);\r
+ }\r
+\r
+ if (strb.toString().length() > 32767) {\r
+ return ErrorEval.VALUE_INVALID;\r
+ }\r
+\r
+ return new StringEval(strb.toString());\r
+ }\r
+}\r
--- /dev/null
+/* ====================================================================\r
+ Licensed to the Apache Software Foundation (ASF) under one or more\r
+ contributor license agreements. See the NOTICE file distributed with\r
+ this work for additional information regarding copyright ownership.\r
+ The ASF licenses this file to You under the Apache License, Version 2.0\r
+ (the "License"); you may not use this file except in compliance with\r
+ the License. You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+==================================================================== */\r
+\r
+package org.apache.poi.ss.formula.functions;\r
+\r
+/**\r
+ * Tests REPT() as loaded from a test data spreadsheet.<p/>\r
+ *\r
+ * @author cedric dot walter @ gmail dot com\r
+ */\r
+public class TestReptFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {\r
+\r
+ @Override\r
+ protected String getFilename() {\r
+ return "ReptFunctionTestCaseData.xls";\r
+ }\r
+}
\ No newline at end of file