summaryrefslogtreecommitdiff
path: root/NxWidgets
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
parent047cdbcf3dfb493818e2eb33db25a2a70f2bb15d (diff)
downloadnuttx-2bec876c8e5e6abdca9859ed56b18a7d1a71feb8.tar.gz
nuttx-2bec876c8e5e6abdca9859ed56b18a7d1a71feb8.tar.bz2
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')
-rw-r--r--NxWidgets/libnxwidgets/include/cnxstring.hxx20
-rw-r--r--NxWidgets/libnxwidgets/src/cnxstring.cxx7
2 files changed, 20 insertions, 7 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.
diff --git a/NxWidgets/libnxwidgets/src/cnxstring.cxx b/NxWidgets/libnxwidgets/src/cnxstring.cxx
index 8548de636..4962858fa 100644
--- a/NxWidgets/libnxwidgets/src/cnxstring.cxx
+++ b/NxWidgets/libnxwidgets/src/cnxstring.cxx
@@ -161,9 +161,9 @@ CStringIterator *CNxString::newStringIterator() const
/**
* 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() + 2) bytes long, in order to
+ * The buffer must be (getAllocSize() + 2) bytes long, in order to
* accommodate the terminator.
*
* @param buffer Buffer to copy the internal char array to.
@@ -677,6 +677,7 @@ CNxString& CNxString::operator=(const CNxString &string)
{
setText(string);
}
+
return *this;
}
@@ -688,7 +689,7 @@ CNxString& CNxString::operator=(const CNxString &string)
* @return This string.
*/
-CNxString& CNxString::operator=(const char *string)
+CNxString& CNxString::operator=(FAR const char *string)
{
setText(string);
return *this;