Repository: conan-io/conan-center-index

Issue:
[request] utfcpp/3.1
### Package Details
  * Package Name/Version: **utfcpp/3.1**
  * Website: **https://github.com/nemtrif/utfcpp**
  * Source code: **https://github.com/nemtrif/utfcpp**


### Description Of The Library / Tool
UTF-8 with C++ in a Portable Way.
This is a small, C++98 compatible generic library. For anybody used to work with STL algorithms and iterators, it should be easy and natural to use. The library has been used a lot in the past ten years both in commercial and open-source projects and is considered feature-complete now.



Discussion:
Hi @AndWass !

Thanks for requesting this package. I see that utfcpp is a header-only project and should be easy the be packaged. Don't you are interested in trying this one? We can help you writing the recipe. Also, we have some examples, for instance toml11: https://github.com/conan-io/conan-center-index/blob/43a118c23113c5f70da7be60b990483aaa09f74f/recipes/toml11/all/conanfile.py

Regards!

Resolving patch:
diff --git a/recipes/utfcpp/all/conanfile.py b/recipes/utfcpp/all/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/utfcpp/all/conanfile.py
@@ -0,0 +1,29 @@
+import os
+from conans import ConanFile, tools
+
+
+class UtfCppConan(ConanFile):
+    name = "utfcpp"
+    url = "https://github.com/conan-io/conan-center-index"
+    homepage = "https://github.com/nemtrif/utfcpp"
+    description = "UTF-8 with C++ in a Portable Way"
+    settings = "os", "compiler", "arch", "build_type"
+    topics = ("utf", "utf8", "unicode", "text")
+    license = "BSL-1.0"
+    no_copy_source = True
+
+    _source_subfolder = "source_subfolder"
+
+    def source(self):
+        tools.get(**self.conan_data["sources"][self.version])
+        extracted_dir = self.name + "-" + self.version
+        os.rename(extracted_dir, self._source_subfolder)
+
+    def package(self):
+        self.copy("*.h",
+                  dst="include",
+                  src=os.path.join(self._source_subfolder, "source"))
+        self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
+
+    def package_id(self):
+        self.info.header_only()
\ No newline at end of file


Test patch:
diff --git a/recipes/utfcpp/all/test_package/CMakeLists.txt b/recipes/utfcpp/all/test_package/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/recipes/utfcpp/all/test_package/CMakeLists.txt
@@ -0,0 +1,11 @@
+  
+cmake_minimum_required(VERSION 3.1)
+project(utfcpptest CXX)
+
+set(CMAKE_CXX_STANDARD 11)
+
+include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
+conan_basic_setup()
+
+add_executable(${PROJECT_NAME} ${PROJECT_NAME}.cpp)
+target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
\ No newline at end of file
diff --git a/recipes/utfcpp/all/test_package/conanfile.py b/recipes/utfcpp/all/test_package/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/utfcpp/all/test_package/conanfile.py
@@ -0,0 +1,15 @@
+from conans import ConanFile, CMake
+import os
+
+class UtfCppTestConan(ConanFile):
+    settings = "os", "compiler", "build_type", "arch"
+    generators = "cmake"
+
+    def build(self):
+        cmake = CMake(self)
+        cmake.configure()
+        cmake.build()
+
+    def test(self):
+        os.chdir("bin")
+        self.run(".%sutfcpptest" % os.sep)
\ No newline at end of file
diff --git a/recipes/utfcpp/all/test_package/utfcpptest.cpp b/recipes/utfcpp/all/test_package/utfcpptest.cpp
new file mode 100644
--- /dev/null
+++ b/recipes/utfcpp/all/test_package/utfcpptest.cpp
@@ -0,0 +1,18 @@
+#include "utf8.h"
+#include <iostream>
+#include <string>
+#include <cstdint>
+
+
+using namespace std;
+
+int main(int argc, char** argv)
+{
+    // U+1f600, grinning smiley face
+    std::string text = "\xf0\x9f\x98\x80";
+    bool valid = utf8::is_valid(text.begin(), text.end());
+    std::ptrdiff_t length = utf8::distance(text.begin(), text.end());
+
+    std::cout << "Valid = " << valid << " length = " << length << "\n";
+    return 0;
+}
\ No newline at end of file