(fix) cosmetics
parent
42bf30d05e
commit
8f2bcb6055
|
@ -1,6 +1,6 @@
|
|||
/* NSString+Utilities.h - this file is part of SOGo
|
||||
*
|
||||
* Copyright (C) 2006-2015 Inverse inc.
|
||||
* Copyright (C) 2006-2017 Inverse inc.
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* NSString+Utilities.m - this file is part of SOGo
|
||||
*
|
||||
* Copyright (C) 2006-2015 Inverse inc.
|
||||
* Copyright (C) 2006-2017 Inverse inc.
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -335,8 +335,10 @@ static int cssEscapingCount;
|
|||
// We avoid naming it like the one in SOPE since if the ActiveSync
|
||||
// bundle is loaded, it'll overwrite the one provided by SOPE.
|
||||
//
|
||||
- (NSString *) safeStringByEscapingXMLString: (BOOL) encoreCR
|
||||
- (NSString *) safeStringByEscapingXMLString: (BOOL) encodeCR
|
||||
{
|
||||
NSData *data;
|
||||
|
||||
register unsigned i, len, j;
|
||||
register wchar_t *buf;
|
||||
const wchar_t *chars;
|
||||
|
@ -344,12 +346,13 @@ static int cssEscapingCount;
|
|||
|
||||
if ([self length] == 0) return @"";
|
||||
|
||||
NSData *data = [self dataUsingEncoding:NSUTF32StringEncoding];
|
||||
data = [self dataUsingEncoding: NSUTF32StringEncoding];
|
||||
chars = [data bytes];
|
||||
len = [data length]/4;
|
||||
|
||||
/* check for characters to escape ... */
|
||||
for (i = 0, escapeCount = 0; i < len; i++) {
|
||||
for (i = 0, escapeCount = 0; i < len; i++)
|
||||
{
|
||||
switch (chars[i]) {
|
||||
case '&': case '"': case '<': case '>': case '\r':
|
||||
escapeCount++;
|
||||
|
@ -360,14 +363,16 @@ static int cssEscapingCount;
|
|||
break;
|
||||
}
|
||||
}
|
||||
if (escapeCount == 0 ) {
|
||||
|
||||
/* nothing to escape ... */
|
||||
if (escapeCount == 0 )
|
||||
return [[self copy] autorelease];
|
||||
}
|
||||
|
||||
buf = calloc((len + 5) + (escapeCount * 16), sizeof(wchar_t));
|
||||
for (i = 0, j = 0; i < len; i++) {
|
||||
switch (chars[i]) {
|
||||
for (i = 0, j = 0; i < len; i++)
|
||||
{
|
||||
switch (chars[i])
|
||||
{
|
||||
/* escape special chars */
|
||||
case '&':
|
||||
buf[j] = '&'; j++; buf[j] = 'a'; j++; buf[j] = 'm'; j++;
|
||||
|
@ -386,7 +391,7 @@ static int cssEscapingCount;
|
|||
buf[j] = ';'; j++;
|
||||
break;
|
||||
case '\r':
|
||||
if (encoreCR) // falls back to default if we don't encode
|
||||
if (encodeCR) // falls back to default if we don't encode
|
||||
{
|
||||
buf[j] = '&'; j++; buf[j] = '#'; j++; buf[j] = '1'; j++;
|
||||
buf[j] = '3'; j++; buf[j] = ';'; j++;
|
||||
|
@ -394,17 +399,20 @@ static int cssEscapingCount;
|
|||
}
|
||||
default:
|
||||
/* escape big chars */
|
||||
if (chars[i] > 127) {
|
||||
if (chars[i] > 127)
|
||||
{
|
||||
unsigned char nbuf[32];
|
||||
unsigned int k;
|
||||
|
||||
sprintf((char *)nbuf, "&#%i;", (int)chars[i]);
|
||||
for (k = 0; nbuf[k] != '\0'; k++) {
|
||||
for (k = 0; nbuf[k] != '\0'; k++)
|
||||
{
|
||||
buf[j] = nbuf[k];
|
||||
j++;
|
||||
}
|
||||
}
|
||||
else if (chars[i] == 0x9 || chars[i] == 0xA || chars[i] == 0xD || chars[i] >= 0x20) { // ignore any unsupported control character
|
||||
else if (chars[i] == 0x9 || chars[i] == 0xA || chars[i] == 0xD || chars[i] >= 0x20)
|
||||
{ // ignore any unsupported control character
|
||||
/* nothing to escape */
|
||||
buf[j] = chars[i];
|
||||
j++;
|
||||
|
@ -417,7 +425,6 @@ static int cssEscapingCount;
|
|||
length: (j*sizeof(wchar_t))
|
||||
encoding: NSUTF32StringEncoding
|
||||
freeWhenDone: YES];
|
||||
|
||||
return [self autorelease];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue