Add livebox_util_nl2br function.
authorSung-jae Park <nicesj.park@samsung.com>
Mon, 6 Aug 2012 09:15:10 +0000 (18:15 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Mon, 6 Aug 2012 12:27:44 +0000 (21:27 +0900)
Replace New Line with <BR>

Change-Id: Ia2571b4bcc22f4b23d823727f4cabfdd82676a9d

debian/changelog
include/livebox.h
packaging/liblivebox.spec
src/livebox.c

index 103adb3..2f671c2 100644 (file)
@@ -1,3 +1,10 @@
+livebox (0.0.7) unstable; urgency=low
+
+  * Git: slp/pkgs/l/livebox
+  * Tag: livebox_0.0.7
+
+ -- Sung-jae Park <nicesj.park@samsung.com>  Mon, 06 Aug 2012 21:27:32 +0900
+
 livebox (0.0.6) unstable; urgency=low
 
   * Git: slp/pkgs/l/livebox
index 8304a72..29c8e97 100644 (file)
@@ -90,6 +90,13 @@ extern int livebox_desc_add_block(struct livebox_desc *handle, const char *id, c
  */
 extern int livebox_desc_del_block(struct livebox_desc *handle, int idx);
 
+/*!
+ * \brief Replace '\n' with '<br>'
+ * \param[in] str Source string
+ * \return char* allocated string
+ */
+extern char *livebox_util_nl2br(const char *str);
+
 #ifdef __cplusplus
 }
 #endif
index 203189d..474b7cd 100644 (file)
@@ -1,6 +1,6 @@
 Name: liblivebox
 Summary: Library for the development of a livebox 
-Version: 0.0.6
+Version: 0.0.7
 Release: 1
 Group: main/app
 License: Samsung Proprietary License
index 4afc059..3d69854 100644 (file)
@@ -234,6 +234,60 @@ EAPI int livebox_desc_set_size(struct livebox_desc *handle, const char *id, int
        return block->idx;
 }
 
+EAPI char *livebox_util_nl2br(const char *str)
+{
+       int len;
+       register int i;
+       char *ret;
+       char *ptr;
+
+       if (!str)
+               return NULL;
+
+       len = strlen(str);
+       if (!len)
+               return NULL;
+
+       ret = malloc(len);
+       if (!ret)
+               return NULL;
+
+       ptr = ret;
+       i = 0;
+       while (*str) {
+               switch (*str) {
+               case '\n':
+                       if (len - i < 5) {
+                               char *tmp;
+                               len += len;
+
+                               tmp = realloc(ret, len);
+                               if (!tmp) {
+                                       free(ret);
+                                       return NULL;
+                               }
+
+                               ret = tmp;
+                               ptr = tmp + i;
+                       }
+
+                       strcpy(ptr, "<br>");
+                       ptr += 4;
+                       i += 4;
+                       break;
+               default:
+                       *ptr++ = *str;
+                       i++;
+                       break;
+               }
+
+               str++;
+       }
+       *ptr = '\0';
+
+       return ret;
+}
+
 /*!
  * \return idx
  */