2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.tizenopensource.org/license
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include "calc-main.h"
22 #include "calc-string.h"
29 * Insert str2 to str at index.
31 void string_insert(char *str, int index, char *str2)
33 int buf_size = strlen(str) + strlen(str2) + 1;
34 char *buf = (char *)malloc(buf_size);
38 memset(buf, 0, buf_size);
39 strncpy(buf, str, index);
41 strncat(buf, str2, buf_size - 1 - strlen(buf)); //don't use g_strlcat, because has bug.
42 strncat(buf, str + index, buf_size - 1 - strlen(buf));
49 * Replace a with b in str locally.
51 void string_replace(char *str, char *a, char *b)
54 char buf[BUFLEN] = { 0 };
55 while ((pch = strstr(str, a)) != NULL) {
56 strncpy(buf, str, pch - str);
57 buf[pch - str] = '\0';
58 g_strlcat(buf, b, sizeof(buf));
59 g_strlcat(buf, pch + strlen(a), sizeof(buf));
64 void string_remove_at(char *str, int at, int length)
67 while ((str[i] = str[i + length]) != '\0') {
74 This is redundant comment.
75 Its only use is for Klocwork testing.
76 The comment rete should passed 25%.
77 But we have only one day to do this work.
78 So, sorry, I will delete this comment and add useful comment later.
82 /* @attention DON'T REMOVE
85 char *a = (char *)malloc(42);
86 if (a) { sprintf(a, "%d", i); }
93 if (i != 0)//last digit number
95 //if ((new_node) && (CALCULATOR_GET_NODE_DATA(new_node)->tmp_result == PI || CALCULATOR_GET_NODE_DATA(new_node)->tmp_result == EXPONENT))
96 if ((new_node) && (FLOAT_EQUAL(CALCULATOR_GET_NODE_DATA(new_node)->tmp_result,PI)
97 || FLOAT_EQUAL(CALCULATOR_GET_NODE_DATA(new_node)->tmp_result, EXPONENT)))
99 node_data = g_malloc0(sizeof(calculator_node_data_t));
100 node_data->cur_operator = 'x';
101 node_data->negative_flag = 1;
102 node_data->operator_type = OPERATOR_TYPE_BINARY;
103 node_data->node_calcu_priority = CALCULATOR_CALCULATE_PRIORITY_MIDDLE;
104 tree = g_node_new(node_data);
108 __calculator_calculate_insert_node(&last_node, tree, new_node);
112 g_node_insert(tree, -1, new_node);
113 CALCULATOR_GET_NODE_DATA(tree)->children_num++;
120 memset(tmp, 0x00, sizeof(tmp));
123 node_data = g_malloc0(sizeof(calculator_node_data_t));
124 node_data->tmp_result = factor;
125 node_data->negative_flag = 1;
126 node_data->negative_flag *= negative_sign;
128 new_node = g_node_new(node_data);
130 if (last_node != NULL)
132 if (CALCULATOR_GET_NODE_DATA(last_node)->children_num > CALCULATOR_GET_NODE_DATA(last_node)->operator_type)
134 strcat(error_msg, CALC_MSG_SYNTAX_ERROR);
139 g_node_insert(last_node, -1, new_node);
140 CALCULATOR_GET_NODE_DATA(last_node)->children_num++;