[muscle] Re: RFC: String class
- From: "Mika Lindqvist" <linki@xxxxxxx>
- To: <muscle@xxxxxxxxxxxxx>
- Date: Tue, 28 Oct 2003 22:21:08 +0200
Damn I hate this Ecartis...
>>> Paste
Index: src/muscle/util/String.cpp
===================================================================
RCS file: /cvsroot/unizone/unizone/src/muscle/util/String.cpp,v
retrieving revision 1.5
diff -u -r1.5 String.cpp
--- src/muscle/util/String.cpp 22 Aug 2003 20:41:06 -0000 1.5
+++ src/muscle/util/String.cpp 28 Oct 2003 19:44:50 -0000
@@ -486,6 +486,66 @@
return B_NO_ERROR;
}
+String String::fromNumber(uint64 num)
+{
+ String temp;
+ char buff[64];
+#if defined(__MWERKS__) || defined(WIN32)
+ sprintf(buff, "%Lu", num);
+#else
+ sprintf(buff, "%llu", num);
+#endif
+ temp.SetCstr(buff);
+ return temp;
+}
+
+String String::fromNumber(int64 num)
+{
+ String temp;
+ char buff[64];
+#if defined(__MWERKS__) || defined(WIN32)
+ sprintf(buff, "%Li", num);
+#else
+ sprintf(buff, "%lli", num);
+#endif
+ temp.SetCstr(buff);
+ return temp;
+}
+
+String String::fromNumber(uint32 num)
+{
+ String temp;
+ char buff[64];
+ sprintf(buff, "%lu", num);
+ temp.SetCstr(buff);
+ return temp;
+}
+
+String String::fromNumber(int32 num)
+{
+ String temp;
+ char buff[64];
+ sprintf(buff, "%li", num);
+ temp.SetCstr(buff);
+ return temp;
+}
+
+String String::fromNumber(double num, unsigned int prec)
+{
+ String temp;
+ char buff[64];
+ char format[10];
+ sprintf(format, "%%.%uf", prec);
+ sprintf(buff, format, num);
+ temp.SetCstr(buff);
+ return temp;
+}
+
+String String::fromNumber(float num, unsigned int prec)
+{
+ return String::fromNumber((double) num, prec);
+}
+
/*--- ElfHash ---------------------------------------------------
* The published hash algorithm used in the UNIX ELF format
* for object files. Accepts a pointer to a string to be hashed
Index: src/muscle/util/String.h
===================================================================
RCS file: /cvsroot/unizone/unizone/src/muscle/util/String.h,v
retrieving revision 1.5
diff -u -r1.5 String.h
--- src/muscle/util/String.h 22 Aug 2003 20:41:06 -0000 1.5
+++ src/muscle/util/String.h 28 Oct 2003 19:44:51 -0000
@@ -148,6 +148,21 @@
* automatically by scanning the string.
*/
status_t SetCstr(const char * str, uint32 maxLen = ((uint32)-1));
+
+ /** Return new String from given numeric variable
+ * @param num The numeric variable to copy from
+ */
+ static String fromNumber(uint64 num);
+ static String fromNumber(int64 num);
+ static String fromNumber(uint32 num);
+ static String fromNumber(int32 num);
+
+ /** Return new String from given numeric variable
+ * @param num The numeric variable to copy from
+ * @param prec The precision of resulting string, defaults to 2.
+ */
+ static String fromNumber(double num, unsigned int prec = 2);
+ static String fromNumber(float num, unsigned int prec = 2);
/** Returns true iff this string ends with (suffix) */
bool EndsWith(const String &suffix) const;
<<< Paste
> -- Binary/unsupported file stripped by Ecartis --
> -- Type: application/x-zip-compressed
> -- File: StringFromNumber.zip
>
>
- References:
- [muscle] RFC: String class
- From: Mika Lindqvist
Other related posts:
- » [muscle] RFC: String class
- » [muscle] Re: RFC: String class
- [muscle] RFC: String class
- From: Mika Lindqvist