summaryrefslogtreecommitdiff
path: root/indra/llcommon
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llcommon')
-rw-r--r--indra/llcommon/llbase64.cpp43
-rw-r--r--indra/llcommon/llbase64.h19
-rw-r--r--indra/llcommon/llsdserialize_xml.cpp1
-rw-r--r--indra/llcommon/llstring.h10
4 files changed, 68 insertions, 5 deletions
diff --git a/indra/llcommon/llbase64.cpp b/indra/llcommon/llbase64.cpp
new file mode 100644
index 0000000000..88e9d960a2
--- /dev/null
+++ b/indra/llcommon/llbase64.cpp
@@ -0,0 +1,43 @@
+/**
+ * @file llbase64.cpp
+ * @brief Wrapper for apr base64 encoding that returns a std::string
+ * @author James Cook
+ *
+ * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
+ * $License$
+ */
+
+#include "linden_common.h"
+
+#include "llbase64.h"
+
+#include <string>
+
+#include "apr-1/apr_base64.h"
+
+
+// static
+std::string LLBase64::encode(const U8* input, size_t input_size)
+{
+ std::string output;
+ if (input
+ && input_size > 0)
+ {
+ // Yes, it returns int.
+ int b64_buffer_length = apr_base64_encode_len(input_size);
+ char* b64_buffer = new char[b64_buffer_length];
+
+ // This is faster than apr_base64_encode() if you know
+ // you're not on an EBCDIC machine. Also, the output is
+ // null terminated, even though the documentation doesn't
+ // specify. See apr_base64.c for details. JC
+ b64_buffer_length = apr_base64_encode_binary(
+ b64_buffer,
+ input,
+ input_size);
+ output.assign(b64_buffer);
+ delete[] b64_buffer;
+ }
+ return output;
+}
+
diff --git a/indra/llcommon/llbase64.h b/indra/llcommon/llbase64.h
new file mode 100644
index 0000000000..6e8b817ba7
--- /dev/null
+++ b/indra/llcommon/llbase64.h
@@ -0,0 +1,19 @@
+/**
+ * @file llbase64.h
+ * @brief Wrapper for apr base64 encoding that returns a std::string
+ * @author James Cook
+ *
+ * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
+ * $License$
+ */
+
+#ifndef LLBASE64_H
+#define LLBASE64_h
+
+class LLBase64
+{
+public:
+ static std::string encode(const U8* input, size_t input_size);
+};
+
+#endif
diff --git a/indra/llcommon/llsdserialize_xml.cpp b/indra/llcommon/llsdserialize_xml.cpp
index c21b8f19a4..796cd9f9f4 100644
--- a/indra/llcommon/llsdserialize_xml.cpp
+++ b/indra/llcommon/llsdserialize_xml.cpp
@@ -171,6 +171,7 @@ S32 LLSDXMLFormatter::format_impl(const LLSD& data, std::ostream& ostr, U32 opti
else
{
// *FIX: memory inefficient.
+ // *TODO: convert to use LLBase64
ostr << pre << "<binary encoding=\"base64\">";
int b64_buffer_length = apr_base64_encode_len(buffer.size());
char* b64_buffer = new char[b64_buffer_length];
diff --git a/indra/llcommon/llstring.h b/indra/llcommon/llstring.h
index a381af74d0..6e9ea0b5a0 100644
--- a/indra/llcommon/llstring.h
+++ b/indra/llcommon/llstring.h
@@ -904,7 +904,7 @@ void LLStringBase<T>::replaceNonstandardASCII( std::basic_string<T>& string, T r
//static
template<class T>
-void LLStringBase<T>::replaceTabsWithSpaces( std::basic_string<T>& string, size_type spaces_per_tab )
+void LLStringBase<T>::replaceTabsWithSpaces( std::basic_string<T>& str, size_type spaces_per_tab )
{
llassert( spaces_per_tab >= 0 );
@@ -913,19 +913,19 @@ void LLStringBase<T>::replaceTabsWithSpaces( std::basic_string<T>& string, size_
LLStringBase<T> out_str;
// Replace tabs with spaces
- for (size_type i = 0; i < string.length(); i++)
+ for (size_type i = 0; i < str.length(); i++)
{
- if (string[i] == TAB)
+ if (str[i] == TAB)
{
for (size_type j = 0; j < spaces_per_tab; j++)
out_str += SPACE;
}
else
{
- out_str += string[i];
+ out_str += str[i];
}
}
- string = out_str;
+ str = out_str;
}
//static