summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-06-04 14:58:40 +0200
committerSven Gothel <[email protected]>2020-06-04 14:58:40 +0200
commit66c34a6229c9d541f1ae8900b357f953edfa54cd (patch)
tree03dec1a8edf5da4cb795a62bce110ec5625f1354
parente6d1ec031165eb10471426a71f1640ebb8e1159f (diff)
BasicTypes: Rename getUTF8String(..) -> decodeUTF8String(..): Adding API doc section with reference to used algov2.1.2
-rw-r--r--api/direct_bt/BasicTypes.hpp6
-rw-r--r--examples/direct_bt_scanner00/dbt_scanner00.cpp2
-rw-r--r--examples/direct_bt_scanner10/dbt_scanner10.cpp2
-rw-r--r--examples/java/ScannerTinyB01.java2
-rw-r--r--examples/java/ScannerTinyB10.java2
-rw-r--r--java/jni/direct_bt/DBTUtils.cxx4
-rw-r--r--java/org/tinyb/BluetoothUtils.java6
-rw-r--r--src/direct_bt/BasicTypes.cpp2
8 files changed, 17 insertions, 9 deletions
diff --git a/api/direct_bt/BasicTypes.hpp b/api/direct_bt/BasicTypes.hpp
index 231d8e03..e75b537b 100644
--- a/api/direct_bt/BasicTypes.hpp
+++ b/api/direct_bt/BasicTypes.hpp
@@ -414,8 +414,12 @@ namespace direct_bt {
* In case a non UTF-8 character has been detected,
* the content will be cut off and the decoding loop ends.
* </p>
+ * <p>
+ * Method utilizes a finite state machine detecting variable length UTF-8 codes.
+ * See Bjoern Hoehrmann's site <http://bjoern.hoehrmann.de/utf-8/decoder/dfa/> for details.
+ * </p>
*/
- std::string getUTF8String(const uint8_t *buffer, const size_t buffer_size);
+ std::string decodeUTF8String(const uint8_t *buffer, const size_t buffer_size);
} // namespace direct_bt
diff --git a/examples/direct_bt_scanner00/dbt_scanner00.cpp b/examples/direct_bt_scanner00/dbt_scanner00.cpp
index 8f8b4db3..29005d5c 100644
--- a/examples/direct_bt_scanner00/dbt_scanner00.cpp
+++ b/examples/direct_bt_scanner00/dbt_scanner00.cpp
@@ -271,7 +271,7 @@ int main(int argc, char *argv[])
if( serviceChar.hasProperties(GATTCharacteristic::PropertyBitVal::Read) ) {
POctets value(GATTHandler::ClientMaxMTU, 0);
if( serviceChar.readValue(value) ) {
- std::string sval = getUTF8String(value.get_ptr(), value.getSize());
+ std::string sval = decodeUTF8String(value.get_ptr(), value.getSize());
fprintf(stderr, " [%2.2d.%2.2d] Value: %s ('%s')\n", (int)i, (int)j, value.toString().c_str(), sval.c_str());
}
}
diff --git a/examples/direct_bt_scanner10/dbt_scanner10.cpp b/examples/direct_bt_scanner10/dbt_scanner10.cpp
index 2eaecbd5..2905f07c 100644
--- a/examples/direct_bt_scanner10/dbt_scanner10.cpp
+++ b/examples/direct_bt_scanner10/dbt_scanner10.cpp
@@ -274,7 +274,7 @@ static void processConnectedDevice(std::shared_ptr<DBTDevice> device) {
if( serviceChar.hasProperties(GATTCharacteristic::PropertyBitVal::Read) ) {
POctets value(GATTHandler::ClientMaxMTU, 0);
if( serviceChar.readValue(value) ) {
- std::string sval = getUTF8String(value.get_ptr(), value.getSize());
+ std::string sval = decodeUTF8String(value.get_ptr(), value.getSize());
fprintf(stderr, " [%2.2d.%2.2d] Value: %s ('%s')\n", (int)i, (int)j, value.toString().c_str(), sval.c_str());
}
}
diff --git a/examples/java/ScannerTinyB01.java b/examples/java/ScannerTinyB01.java
index 18ad3955..0f392efe 100644
--- a/examples/java/ScannerTinyB01.java
+++ b/examples/java/ScannerTinyB01.java
@@ -309,7 +309,7 @@ public class ScannerTinyB01 {
final List<String> properties = Arrays.asList(serviceChar.getFlags());
if( properties.contains("read") ) {
final byte[] value = serviceChar.readValue();
- final String svalue = BluetoothUtils.getUTF8String(value, 0, value.length);
+ final String svalue = BluetoothUtils.decodeUTF8String(value, 0, value.length);
System.err.printf(" [%02d.%02d] Value: %s ('%s')\n",
i, j, BluetoothUtils.bytesHexString(value, true, true), svalue);
}
diff --git a/examples/java/ScannerTinyB10.java b/examples/java/ScannerTinyB10.java
index 87912750..231ac896 100644
--- a/examples/java/ScannerTinyB10.java
+++ b/examples/java/ScannerTinyB10.java
@@ -220,7 +220,7 @@ public class ScannerTinyB10 {
final List<String> properties = Arrays.asList(serviceChar.getFlags());
if( properties.contains("read") ) {
final byte[] value = serviceChar.readValue();
- final String svalue = BluetoothUtils.getUTF8String(value, 0, value.length);
+ final String svalue = BluetoothUtils.decodeUTF8String(value, 0, value.length);
System.err.printf(" [%02d.%02d] Value: %s ('%s')\n",
i, j, BluetoothUtils.bytesHexString(value, true, true), svalue);
}
diff --git a/java/jni/direct_bt/DBTUtils.cxx b/java/jni/direct_bt/DBTUtils.cxx
index 5b53dbc6..876cd4ff 100644
--- a/java/jni/direct_bt/DBTUtils.cxx
+++ b/java/jni/direct_bt/DBTUtils.cxx
@@ -33,7 +33,7 @@
#include "helper_base.hpp"
#include "helper_dbt.hpp"
-jstring Java_org_tinyb_BluetoothUtils_getUTF8String(JNIEnv *env, jclass clazz, jbyteArray jbuffer, jint offset, jint size) {
+jstring Java_org_tinyb_BluetoothUtils_decodeUTF8String(JNIEnv *env, jclass clazz, jbyteArray jbuffer, jint offset, jint size) {
(void)clazz;
const int buffer_size = env->GetArrayLength(jbuffer);
@@ -51,7 +51,7 @@ jstring Java_org_tinyb_BluetoothUtils_getUTF8String(JNIEnv *env, jclass clazz, j
if( NULL == buffer_ptr ) {
throw direct_bt::InternalError("GetPrimitiveArrayCritical(byte array) is null", E_FILE_LINE);
}
- std::string sres = direct_bt::getUTF8String(buffer_ptr+offset, size);
+ std::string sres = direct_bt::decodeUTF8String(buffer_ptr+offset, size);
return from_string_to_jstring(env, sres);
}
diff --git a/java/org/tinyb/BluetoothUtils.java b/java/org/tinyb/BluetoothUtils.java
index e187ea3a..c1cf5a85 100644
--- a/java/org/tinyb/BluetoothUtils.java
+++ b/java/org/tinyb/BluetoothUtils.java
@@ -79,7 +79,11 @@ public class BluetoothUtils {
* In case a non UTF-8 character has been detected,
* the content will be cut off and the decoding loop ends.
* </p>
+ * <p>
+ * Method utilizes a finite state machine detecting variable length UTF-8 codes.
+ * See <a href="http://bjoern.hoehrmann.de/utf-8/decoder/dfa/">Bjoern Hoehrmann's site</a> for details.
+ * </p>
*/
- public static native String getUTF8String(final byte[] buffer, final int offset, final int size);
+ public static native String decodeUTF8String(final byte[] buffer, final int offset, final int size);
}
diff --git a/src/direct_bt/BasicTypes.cpp b/src/direct_bt/BasicTypes.cpp
index ccca8db4..47070b35 100644
--- a/src/direct_bt/BasicTypes.cpp
+++ b/src/direct_bt/BasicTypes.cpp
@@ -347,7 +347,7 @@ std::string direct_bt::trimCopy(const std::string &_s) {
static uint32_t dfa_utf8_decode(uint32_t & state, uint32_t & codep, const uint32_t byte_value);
-std::string direct_bt::getUTF8String(const uint8_t *buffer, const size_t buffer_size) {
+std::string direct_bt::decodeUTF8String(const uint8_t *buffer, const size_t buffer_size) {
uint32_t codepoint;
uint32_t state = UTF8_ACCEPT;
size_t byte_count;