summaryrefslogtreecommitdiff
path: root/NxWidgets/libnxwidgets/include
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-07-24 14:57:38 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-07-24 14:57:38 -0600
commit2bec876c8e5e6abdca9859ed56b18a7d1a71feb8 (patch)
tree952de3aa265f21b0ad7f5d6af7f383c05a14d1ad /NxWidgets/libnxwidgets/include
parent047cdbcf3dfb493818e2eb33db25a2a70f2bb15d (diff)
downloadpx4-nuttx-2bec876c8e5e6abdca9859ed56b18a7d1a71feb8.tar.gz
px4-nuttx-2bec876c8e5e6abdca9859ed56b18a7d1a71feb8.tar.bz2
px4-nuttx-2bec876c8e5e6abdca9859ed56b18a7d1a71feb8.zip
NxWidgets::CNxString: Add a getAllocSize() method to make it easier to convert CNxStrings to NUL-terminated C strings
Diffstat (limited to 'NxWidgets/libnxwidgets/include')
-rw-r--r--NxWidgets/libnxwidgets/include/cnxstring.hxx20
1 files changed, 16 insertions, 4 deletions
diff --git a/NxWidgets/libnxwidgets/include/cnxstring.hxx b/NxWidgets/libnxwidgets/include/cnxstring.hxx
index 50adea21c..2fa230ab1 100644
--- a/NxWidgets/libnxwidgets/include/cnxstring.hxx
+++ b/NxWidgets/libnxwidgets/include/cnxstring.hxx
@@ -239,9 +239,9 @@ namespace NXWidgets
/**
* Copy the internal array to the supplied buffer. The buffer must be
* large enough to contain the full text in the string. The
- * getByteCount() method can be used to obtain the length of the string.
+ * getAllocSize() method can be used to obtain the length of the string.
* Unlike the CNxString class, the char array is null-terminated.
- * The buffer must be (getByteCount() + 1) bytes long, in order to
+ * The buffer must be (getAllocSize() + 1) bytes long, in order to
* accommodate the terminator.
*
* @param buffer Buffer to copy the internal char array to.
@@ -322,12 +322,24 @@ namespace NXWidgets
* @return The length of the string.
*/
- inline const int getLength(void) const
+ inline const unsigned int getLength(void) const
{
return m_stringLength;
};
/**
+ * Get the size of a buffer (in bytes) required in order to copy the
+ * internal string into an the array. This is normally used in
+ * conjunction with copyToCharArray(). Note that the returned size
+ * includes additional byte(s) to hold NUL termination.
+ */
+
+ inline const unsigned int getAllocSize(void) const
+ {
+ return sizeof(nxwidget_char_t) * (m_stringLength + 1);
+ }
+
+ /**
* Get the character at the specified index. This function is useful
* for finding the occasional character at an index, but for iterating
* over strings it is exceptionally slow. The newStringIterator()
@@ -463,7 +475,7 @@ namespace NXWidgets
* @return This string.
*/
- CNxString& operator=(nxwidget_char_t letter);
+ CNxString &operator=(nxwidget_char_t letter);
/**
* Compares this string to the argument.