NSString literals

This commit is contained in:
Dmitry Serov 2017-07-08 15:06:32 +07:00
parent 80a2adc074
commit 87b6c451ac
7 changed files with 37 additions and 37 deletions

View File

@ -978,7 +978,7 @@ static void removeKeRangerRansomware()
if (result != TR_PARSE_OK) if (result != TR_PARSE_OK)
{ {
if (result == TR_PARSE_DUPLICATE) if (result == TR_PARSE_DUPLICATE)
[self duplicateOpenAlert: [NSString stringWithUTF8String: info.name]]; [self duplicateOpenAlert: @(info.name)];
else if (result == TR_PARSE_ERR) else if (result == TR_PARSE_ERR)
{ {
if (type != ADD_AUTO) if (type != ADD_AUTO)
@ -1097,7 +1097,7 @@ static void removeKeRangerRansomware()
if ((duplicateTorrent = tr_torrentFindFromMagnetLink(fLib, [address UTF8String]))) if ((duplicateTorrent = tr_torrentFindFromMagnetLink(fLib, [address UTF8String])))
{ {
const tr_info * info = tr_torrentInfo(duplicateTorrent); const tr_info * info = tr_torrentInfo(duplicateTorrent);
NSString * name = (info != NULL && info->name != NULL) ? [NSString stringWithUTF8String: info->name] : nil; NSString * name = (info != NULL && info->name != NULL) ? @(info->name) : nil;
[self duplicateOpenMagnetAlert: address transferName: name]; [self duplicateOpenMagnetAlert: address transferName: name];
return; return;
} }
@ -4716,7 +4716,7 @@ static void removeKeRangerRansomware()
{ {
NSString * location = nil; NSString * location = nil;
if (tr_torrentGetDownloadDir(torrentStruct) != NULL) if (tr_torrentGetDownloadDir(torrentStruct) != NULL)
location = [NSString stringWithUTF8String: tr_torrentGetDownloadDir(torrentStruct)]; location = @(tr_torrentGetDownloadDir(torrentStruct));
Torrent * torrent = [[Torrent alloc] initWithTorrentStruct: torrentStruct location: location lib: fLib]; Torrent * torrent = [[Torrent alloc] initWithTorrentStruct: torrentStruct location: location lib: fLib];

View File

@ -107,7 +107,7 @@
//only useful when one torrent //only useful when one torrent
if (count == 1) if (count == 1)
{ {
name = [NSString stringWithUTF8String: info.name]; name = @(info.name);
folder = info.isFolder; folder = info.isFolder;
} }
} }

View File

@ -205,14 +205,14 @@
for (tr_log_message * currentMessage = messages; currentMessage != NULL; currentMessage = currentMessage->next) for (tr_log_message * currentMessage = messages; currentMessage != NULL; currentMessage = currentMessage->next)
{ {
NSString * name = currentMessage->name != NULL ? [NSString stringWithUTF8String: currentMessage->name] NSString * name = currentMessage->name != NULL ? @(currentMessage->name)
: [[NSProcessInfo processInfo] processName]; : [[NSProcessInfo processInfo] processName];
NSString * file = [[[NSString stringWithUTF8String: currentMessage->file] lastPathComponent] stringByAppendingFormat: @":%d", NSString * file = [[@(currentMessage->file) lastPathComponent] stringByAppendingFormat: @":%d",
currentMessage->line]; currentMessage->line];
NSDictionary * message = [NSDictionary dictionaryWithObjectsAndKeys: NSDictionary * message = [NSDictionary dictionaryWithObjectsAndKeys:
[NSString stringWithUTF8String: currentMessage->message], @"Message", @(currentMessage->message), @"Message",
[NSDate dateWithTimeIntervalSince1970: currentMessage->when], @"Date", [NSDate dateWithTimeIntervalSince1970: currentMessage->when], @"Date",
@(currentIndex++), @"Index", //more accurate when sorting by date @(currentIndex++), @"Index", //more accurate when sorting by date
@(currentMessage->level), @"Level", @(currentMessage->level), @"Level",

View File

@ -38,7 +38,7 @@
+ (NSString *) ellipsis + (NSString *) ellipsis
{ {
return [NSString stringWithUTF8String: "\xE2\x80\xA6"]; return @"\xE2\x80\xA6";
} }
- (NSString *) stringByAppendingEllipsis - (NSString *) stringByAppendingEllipsis
@ -103,7 +103,7 @@
if ((int)ratio == TR_RATIO_NA) if ((int)ratio == TR_RATIO_NA)
return NSLocalizedString(@"N/A", "No Ratio"); return NSLocalizedString(@"N/A", "No Ratio");
else if ((int)ratio == TR_RATIO_INF) else if ((int)ratio == TR_RATIO_INF)
return [NSString stringWithUTF8String: "\xE2\x88\x9E"]; return @"\xE2\x88\x9E";
else else
{ {
if (ratio < 10.0) if (ratio < 10.0)

View File

@ -1224,10 +1224,10 @@
[fDefaults setBool: encryptionMode == TR_ENCRYPTION_REQUIRED forKey: @"EncryptionRequire"]; [fDefaults setBool: encryptionMode == TR_ENCRYPTION_REQUIRED forKey: @"EncryptionRequire"];
//download directory //download directory
NSString * downloadLocation = [[NSString stringWithUTF8String: tr_sessionGetDownloadDir(fHandle)] stringByStandardizingPath]; NSString * downloadLocation = [@(tr_sessionGetDownloadDir(fHandle)) stringByStandardizingPath];
[fDefaults setObject: downloadLocation forKey: @"DownloadFolder"]; [fDefaults setObject: downloadLocation forKey: @"DownloadFolder"];
NSString * incompleteLocation = [[NSString stringWithUTF8String: tr_sessionGetIncompleteDir(fHandle)] stringByStandardizingPath]; NSString * incompleteLocation = [@(tr_sessionGetIncompleteDir(fHandle)) stringByStandardizingPath];
[fDefaults setObject: incompleteLocation forKey: @"IncompleteDownloadFolder"]; [fDefaults setObject: incompleteLocation forKey: @"IncompleteDownloadFolder"];
const BOOL useIncomplete = tr_sessionIsIncompleteDirEnabled(fHandle); const BOOL useIncomplete = tr_sessionIsIncompleteDirEnabled(fHandle);
@ -1320,7 +1320,7 @@
const BOOL blocklist = tr_blocklistIsEnabled(fHandle); const BOOL blocklist = tr_blocklistIsEnabled(fHandle);
[fDefaults setBool: blocklist forKey: @"BlocklistNew"]; [fDefaults setBool: blocklist forKey: @"BlocklistNew"];
NSString * blocklistURL = [NSString stringWithUTF8String: tr_blocklistGetURL(fHandle)]; NSString * blocklistURL = @(tr_blocklistGetURL(fHandle));
[fDefaults setObject: blocklistURL forKey: @"BlocklistURL"]; [fDefaults setObject: blocklistURL forKey: @"BlocklistURL"];
//seed ratio //seed ratio
@ -1360,7 +1360,7 @@
const BOOL doneScriptEnabled = tr_sessionIsTorrentDoneScriptEnabled(fHandle); const BOOL doneScriptEnabled = tr_sessionIsTorrentDoneScriptEnabled(fHandle);
[fDefaults setBool: doneScriptEnabled forKey: @"DoneScriptEnabled"]; [fDefaults setBool: doneScriptEnabled forKey: @"DoneScriptEnabled"];
NSString * doneScriptPath = [NSString stringWithUTF8String: tr_sessionGetTorrentDoneScript(fHandle)]; NSString * doneScriptPath = @(tr_sessionGetTorrentDoneScript(fHandle));
[fDefaults setObject: doneScriptPath forKey: @"DoneScriptPath"]; [fDefaults setObject: doneScriptPath forKey: @"DoneScriptPath"];
//update gui if loaded //update gui if loaded

View File

@ -100,8 +100,8 @@ void metadataCallback(tr_torrent * torrent, void * torrentData)
void renameCallback(tr_torrent * torrent, const char * oldPathCharString, const char * newNameCharString, int error, void * contextInfo) void renameCallback(tr_torrent * torrent, const char * oldPathCharString, const char * newNameCharString, int error, void * contextInfo)
{ {
@autoreleasepool { @autoreleasepool {
NSString * oldPath = [NSString stringWithUTF8String: oldPathCharString]; NSString * oldPath = @(oldPathCharString);
NSString * newName = [NSString stringWithUTF8String: newNameCharString]; NSString * newName = @(newNameCharString);
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
NSDictionary * contextDict = [(NSDictionary *)contextInfo autorelease]; NSDictionary * contextDict = [(NSDictionary *)contextInfo autorelease];
@ -119,7 +119,7 @@ bool trashDataFile(const char * filename, tr_error ** error)
@autoreleasepool @autoreleasepool
{ {
NSError * localError; NSError * localError;
if (![Torrent trashFile: [NSString stringWithUTF8String: filename] error: &localError]) if (![Torrent trashFile: @(filename) error: &localError])
{ {
tr_error_set_literal(error, [localError code], [[localError description] UTF8String]); tr_error_set_literal(error, [localError code], [[localError description] UTF8String]);
return false; return false;
@ -283,7 +283,7 @@ bool trashDataFile(const char * filename, tr_error ** error)
- (NSString *) currentDirectory - (NSString *) currentDirectory
{ {
return [NSString stringWithUTF8String: tr_torrentGetCurrentDir(fHandle)]; return @(tr_torrentGetCurrentDir(fHandle));
} }
- (void) getAvailability: (int8_t *) tab size: (NSInteger) size - (void) getAvailability: (int8_t *) tab size: (NSInteger) size
@ -410,7 +410,7 @@ bool trashDataFile(const char * filename, tr_error ** error)
- (NSString *) magnetLink - (NSString *) magnetLink
{ {
return [NSString stringWithUTF8String: tr_torrentGetMagnetLink(fHandle)]; return @(tr_torrentGetMagnetLink(fHandle));
} }
- (CGFloat) ratio - (CGFloat) ratio
@ -658,7 +658,7 @@ bool trashDataFile(const char * filename, tr_error ** error)
- (NSString *) name - (NSString *) name
{ {
return fInfo->name != NULL ? [NSString stringWithUTF8String: fInfo->name] : fHashString; return fInfo->name != NULL ? @(fInfo->name) : fHashString;
} }
- (BOOL) isFolder - (BOOL) isFolder
@ -706,7 +706,7 @@ bool trashDataFile(const char * filename, tr_error ** error)
NSMutableArray * allTrackers = [NSMutableArray arrayWithCapacity: fInfo->trackerCount]; NSMutableArray * allTrackers = [NSMutableArray arrayWithCapacity: fInfo->trackerCount];
for (NSInteger i=0; i < fInfo->trackerCount; i++) for (NSInteger i=0; i < fInfo->trackerCount; i++)
[allTrackers addObject: [NSString stringWithUTF8String: fInfo->trackers[i].announce]]; [allTrackers addObject: @(fInfo->trackers[i].announce)];
return allTrackers; return allTrackers;
} }
@ -742,7 +742,7 @@ bool trashDataFile(const char * filename, tr_error ** error)
NSUInteger newCount = 0; NSUInteger newCount = 0;
for (NSUInteger i = 0; i < fInfo->trackerCount; i++) for (NSUInteger i = 0; i < fInfo->trackerCount; i++)
{ {
if (![trackers containsObject: [NSString stringWithUTF8String: fInfo->trackers[i].announce]]) if (![trackers containsObject: @(fInfo->trackers[i].announce)])
trackerStructs[newCount++] = fInfo->trackers[i]; trackerStructs[newCount++] = fInfo->trackers[i];
} }
@ -754,12 +754,12 @@ bool trashDataFile(const char * filename, tr_error ** error)
- (NSString *) comment - (NSString *) comment
{ {
return fInfo->comment ? [NSString stringWithUTF8String: fInfo->comment] : @""; return fInfo->comment ? @(fInfo->comment) : @"";
} }
- (NSString *) creator - (NSString *) creator
{ {
return fInfo->creator ? [NSString stringWithUTF8String: fInfo->creator] : @""; return fInfo->creator ? @(fInfo->creator) : @"";
} }
- (NSDate *) dateCreated - (NSDate *) dateCreated
@ -790,7 +790,7 @@ bool trashDataFile(const char * filename, tr_error ** error)
- (NSString *) torrentLocation - (NSString *) torrentLocation
{ {
return fInfo->torrent ? [NSString stringWithUTF8String: fInfo->torrent] : @""; return fInfo->torrent ? @(fInfo->torrent) : @"";
} }
- (NSString *) dataLocation - (NSString *) dataLocation
@ -813,7 +813,7 @@ bool trashDataFile(const char * filename, tr_error ** error)
if (location == NULL) if (location == NULL)
return nil; return nil;
NSString * dataLocation = [NSString stringWithUTF8String: location]; NSString * dataLocation = @(location);
free(location); free(location);
return dataLocation; return dataLocation;
@ -838,7 +838,7 @@ bool trashDataFile(const char * filename, tr_error ** error)
if (location == NULL) if (location == NULL)
return nil; return nil;
NSString * dataLocation = [NSString stringWithUTF8String: location]; NSString * dataLocation = @(location);
free(location); free(location);
return dataLocation; return dataLocation;
@ -946,7 +946,7 @@ bool trashDataFile(const char * filename, tr_error ** error)
return @""; return @"";
NSString * error; NSString * error;
if (!(error = [NSString stringWithUTF8String: fStat->errorString]) if (!(error = @(fStat->errorString))
&& !(error = [NSString stringWithCString: fStat->errorString encoding: NSISOLatin1StringEncoding])) && !(error = [NSString stringWithCString: fStat->errorString encoding: NSISOLatin1StringEncoding]))
error = [NSString stringWithFormat: @"(%@)", NSLocalizedString(@"unreadable error", "Torrent -> error string unreadable")]; error = [NSString stringWithFormat: @"(%@)", NSLocalizedString(@"unreadable error", "Torrent -> error string unreadable")];
@ -970,14 +970,14 @@ bool trashDataFile(const char * filename, tr_error ** error)
[dict setObject: [self name] forKey: @"Name"]; [dict setObject: [self name] forKey: @"Name"];
[dict setObject: @(peer->from) forKey: @"From"]; [dict setObject: @(peer->from) forKey: @"From"];
[dict setObject: [NSString stringWithUTF8String: peer->addr] forKey: @"IP"]; [dict setObject: @(peer->addr) forKey: @"IP"];
[dict setObject: @(peer->port) forKey: @"Port"]; [dict setObject: @(peer->port) forKey: @"Port"];
[dict setObject: @(peer->progress) forKey: @"Progress"]; [dict setObject: @(peer->progress) forKey: @"Progress"];
[dict setObject: @(peer->isSeed) forKey: @"Seed"]; [dict setObject: @(peer->isSeed) forKey: @"Seed"];
[dict setObject: @(peer->isEncrypted) forKey: @"Encryption"]; [dict setObject: @(peer->isEncrypted) forKey: @"Encryption"];
[dict setObject: @(peer->isUTP) forKey: @"uTP"]; [dict setObject: @(peer->isUTP) forKey: @"uTP"];
[dict setObject: [NSString stringWithUTF8String: peer->client] forKey: @"Client"]; [dict setObject: @(peer->client) forKey: @"Client"];
[dict setObject: [NSString stringWithUTF8String: peer->flagStr] forKey: @"Flags"]; [dict setObject: @(peer->flagStr) forKey: @"Flags"];
if (peer->isUploadingTo) if (peer->isUploadingTo)
[dict setObject: @(peer->rateToPeer_KBps) forKey: @"UL To Rate"]; [dict setObject: @(peer->rateToPeer_KBps) forKey: @"UL To Rate"];
@ -1008,7 +1008,7 @@ bool trashDataFile(const char * filename, tr_error ** error)
NSMutableDictionary * dict = [NSMutableDictionary dictionaryWithCapacity: 3]; NSMutableDictionary * dict = [NSMutableDictionary dictionaryWithCapacity: 3];
[dict setObject: [self name] forKey: @"Name"]; [dict setObject: [self name] forKey: @"Name"];
[dict setObject: [NSString stringWithUTF8String: fInfo->webseeds[i]] forKey: @"Address"]; [dict setObject: @(fInfo->webseeds[i]) forKey: @"Address"];
if (dlSpeeds[i] != -1.0) if (dlSpeeds[i] != -1.0)
[dict setObject: @(dlSpeeds[i]) forKey: @"DL From Rate"]; [dict setObject: @(dlSpeeds[i]) forKey: @"DL From Rate"];
@ -1635,7 +1635,7 @@ bool trashDataFile(const char * filename, tr_error ** error)
for (int i=0; i < count; ++i) for (int i=0; i < count; ++i)
{ {
NSString * tracker = [NSString stringWithUTF8String: stats[i].host]; NSString * tracker = @(stats[i].host);
if (!best || [tracker localizedCaseInsensitiveCompare: best] == NSOrderedAscending) if (!best || [tracker localizedCaseInsensitiveCompare: best] == NSOrderedAscending)
best = tracker; best = tracker;
} }
@ -1762,7 +1762,7 @@ bool trashDataFile(const char * filename, tr_error ** error)
{ {
tr_file * file = &fInfo->files[i]; tr_file * file = &fInfo->files[i];
NSString * fullPath = [NSString stringWithUTF8String: file->name]; NSString * fullPath = @(file->name);
NSArray * pathComponents = [fullPath pathComponents]; NSArray * pathComponents = [fullPath pathComponents];
if (!tempNode) if (!tempNode)

View File

@ -67,12 +67,12 @@
- (NSString *) host - (NSString *) host
{ {
return [NSString stringWithUTF8String: fStat.host]; return @(fStat.host);
} }
- (NSString *) fullAnnounceAddress - (NSString *) fullAnnounceAddress
{ {
return [NSString stringWithUTF8String: fStat.announce]; return @(fStat.announce);
} }
- (NSInteger) tier - (NSInteger) tier
@ -123,7 +123,7 @@
{ {
baseString = NSLocalizedString(@"Announce error", "Tracker last announce"); baseString = NSLocalizedString(@"Announce error", "Tracker last announce");
NSString * errorString = [NSString stringWithUTF8String: fStat.lastAnnounceResult]; NSString * errorString = @(fStat.lastAnnounceResult);
if ([errorString isEqualToString: @""]) if ([errorString isEqualToString: @""])
baseString = [baseString stringByAppendingFormat: @": %@", dateString]; baseString = [baseString stringByAppendingFormat: @": %@", dateString];
else else
@ -213,7 +213,7 @@
{ {
baseString = NSLocalizedString(@"Scrape error", "Tracker last scrape"); baseString = NSLocalizedString(@"Scrape error", "Tracker last scrape");
NSString * errorString = [NSString stringWithUTF8String: fStat.lastScrapeResult]; NSString * errorString = @(fStat.lastScrapeResult);
if ([errorString isEqualToString: @""]) if ([errorString isEqualToString: @""])
baseString = [baseString stringByAppendingFormat: @": %@", dateString]; baseString = [baseString stringByAppendingFormat: @": %@", dateString];
else else