added XMLStringCopy to properly copy NSStrings as xml strings; use it for setting name

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/branches/nsxml_using_libxml2@34505 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Doug Simons 2012-01-12 18:50:56 +00:00
parent 065ac2bce2
commit 8772885b71
3 changed files with 27 additions and 3 deletions

View file

@ -39,10 +39,21 @@
*/
#define XMLSTRING(X) ((const unsigned char*)[X UTF8String])
inline static unsigned char *XMLStringCopy(NSString *source)
{
unsigned int len = [source maximumLengthOfBytesUsingEncoding:NSUTF8StringEncoding] + 1;
unsigned char *xmlstr = malloc(len);
[source getCString:xmlstr maxLength:len encoding:NSUTF8StringEncoding];
return xmlstr;
}
inline static NSString*
StringFromXMLString(const unsigned char *bytes, unsigned length)
{
NSString *str;
if (bytes == NULL)
return @"";
str = [[NSString alloc] initWithBytes: bytes
length: length