From 1510033ab1bf949d611aa9e3e19b81cbe5320ef5 Mon Sep 17 00:00:00 2001 From: Sam Krew Date: Tue, 17 Feb 2015 00:18:14 +0300 Subject: [PATCH] Added utils --- .gitignore | 3 ++- src/util.cc | 15 +++++++++++++++ src/util.h | 9 +++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/util.cc create mode 100644 src/util.h diff --git a/.gitignore b/.gitignore index 08114f3..212cb3b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ libmbus build src/old.cc node_modules -*.build \ No newline at end of file +*.build +npm-debug.log \ No newline at end of file diff --git a/src/util.cc b/src/util.cc new file mode 100644 index 0000000..06585dc --- /dev/null +++ b/src/util.cc @@ -0,0 +1,15 @@ +#include "util.h" +#include +#include + +char *get(v8::Handle value, const char *fallback) { + if (value->IsString()) { + v8::String::AsciiValue string(value); + char *str = (char *) malloc(string.length() + 1); + strcpy(str, *string); + return str; + } + char *str = (char *) malloc(strlen(fallback) + 1); + strcpy(str, fallback); + return str; +} \ No newline at end of file diff --git a/src/util.h b/src/util.h new file mode 100644 index 0000000..252ed47 --- /dev/null +++ b/src/util.h @@ -0,0 +1,9 @@ +#ifndef UTIL_H +#define UTIL_H + +#include +#include + +char *get(v8::Handle value, const char *fallback = ""); + +#endif