mirror of
https://github.com/textmate/textmate.git
synced 2026-04-28 03:00:34 -04:00
Remove NSString* typecast when using to_s helper
This has a small run-time cost but source looks better and theoretically safer code.
This commit is contained in:
@@ -85,8 +85,8 @@ OAK_DEBUG_VAR(AppController_Documents);
|
||||
NSArray* keyValue = [part componentsSeparatedByString:@"="];
|
||||
if([keyValue count] == 2)
|
||||
{
|
||||
std::string key = decode::url_part(to_s((NSString*)[keyValue firstObject]));
|
||||
parameters[key] = decode::url_part(to_s((NSString*)[keyValue lastObject]));
|
||||
std::string key = decode::url_part(to_s([keyValue firstObject]));
|
||||
parameters[key] = decode::url_part(to_s([keyValue lastObject]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -421,7 +421,7 @@ BOOL HasDocumentWindow (NSArray* windows)
|
||||
for(NSDictionary* item in [sender selectedItems])
|
||||
{
|
||||
if(OakIsAlternateKeyOrMouseEvent())
|
||||
[[BundleEditor sharedInstance] revealBundleItem:bundles::lookup(to_s((NSString*)[item objectForKey:@"uuid"]))];
|
||||
[[BundleEditor sharedInstance] revealBundleItem:bundles::lookup(to_s([item objectForKey:@"uuid"]))];
|
||||
else [NSApp sendAction:@selector(performBundleItemWithUUIDString:) to:nil from:[item objectForKey:@"uuid"]];
|
||||
}
|
||||
}
|
||||
@@ -464,7 +464,7 @@ BOOL HasDocumentWindow (NSArray* windows)
|
||||
}
|
||||
else if([item action] == @selector(performBundleItemWithUUIDStringFrom:))
|
||||
{
|
||||
if(bundles::item_ptr bundleItem = bundles::lookup(to_s((NSString*)item.representedObject)))
|
||||
if(bundles::item_ptr bundleItem = bundles::lookup(to_s(item.representedObject)))
|
||||
{
|
||||
if(id textView = [NSApp targetForAction:@selector(hasSelection)])
|
||||
[item updateTitle:[NSString stringWithCxxString:name_with_selection(bundleItem, [textView hasSelection])]];
|
||||
|
||||
@@ -244,7 +244,7 @@ static NSUInteger const kOakSourceIndexFavorites = 1;
|
||||
|
||||
NSMutableDictionary* entry = [item mutableCopy];
|
||||
entry[@"name"] = CreateAttributedStringWithMarkedUpRanges(to_s(name), ranges, NSLineBreakByTruncatingTail);
|
||||
entry[@"folder"] = CreateAttributedStringWithMarkedUpRanges(to_s((NSString*)item[@"folder"]), { }, NSLineBreakByTruncatingHead);
|
||||
entry[@"folder"] = CreateAttributedStringWithMarkedUpRanges(to_s(item[@"folder"]), { }, NSLineBreakByTruncatingHead);
|
||||
ranked.emplace(rank, entry);
|
||||
}
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ static plist::array_t unwrap_array (NSArray* array, NSString* key)
|
||||
{
|
||||
plist::array_t res;
|
||||
for(NSDictionary* dict in array)
|
||||
res.push_back(to_s((NSString*)[dict objectForKey:key]));
|
||||
res.push_back(to_s([dict objectForKey:key]));
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ static NSTimeInterval const kDefaultPollInterval = 3*60*60;
|
||||
if((bundle->installed() && !bundle->has_update()) || installing.find(bundle->uuid()) != installing.end())
|
||||
continue;
|
||||
|
||||
std::string appVersion = to_s((NSString*)[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]);
|
||||
std::string appVersion = to_s([[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]);
|
||||
if(version::less(appVersion, bundle->requires()))
|
||||
{
|
||||
if(!bundle->installed() || bundle == installedBundle)
|
||||
|
||||
@@ -946,9 +946,9 @@ namespace
|
||||
std::vector<document::document_ptr> documents;
|
||||
for(id item in items)
|
||||
{
|
||||
std::string const path = to_s((NSString*)[item objectForKey:@"path"]);
|
||||
std::string const uuid = to_s((NSString*)[item objectForKey:@"identifier"]);
|
||||
std::string const range = to_s((NSString*)[item objectForKey:@"selectionString"]);
|
||||
std::string const path = to_s([item objectForKey:@"path"]);
|
||||
std::string const uuid = to_s([item objectForKey:@"identifier"]);
|
||||
std::string const range = to_s([item objectForKey:@"selectionString"]);
|
||||
|
||||
document::document_ptr doc;
|
||||
if(path == NULL_STR && oak::uuid_t::is_valid(uuid))
|
||||
@@ -1774,7 +1774,7 @@ namespace
|
||||
- (BOOL)performTabDropFromTabBar:(OakTabBarView*)aTabBar atIndex:(NSUInteger)droppedIndex fromPasteboard:(NSPasteboard*)aPasteboard operation:(NSDragOperation)operation
|
||||
{
|
||||
NSDictionary* plist = [aPasteboard propertyListForType:OakDocumentPboardType];
|
||||
document::document_ptr srcDocument = document::find(to_s((NSString*)plist[@"document"]));
|
||||
document::document_ptr srcDocument = document::find(to_s(plist[@"document"]));
|
||||
if(!srcDocument)
|
||||
return NO;
|
||||
|
||||
@@ -1790,7 +1790,7 @@ namespace
|
||||
self.selectedTabIndex = iter - newDocuments.begin();
|
||||
}
|
||||
|
||||
oak::uuid_t srcProjectId = to_s((NSString*)plist[@"collection"]);
|
||||
oak::uuid_t srcProjectId = to_s(plist[@"collection"]);
|
||||
if(operation == NSDragOperationMove && srcProjectId != to_s(self.identifier))
|
||||
{
|
||||
for(DocumentController* delegate in SortedControllers())
|
||||
|
||||
@@ -190,9 +190,9 @@ static bool is_installed (oak::uuid_t const& uuid)
|
||||
return aCompletionHandler(nil);
|
||||
|
||||
NSDictionary* grammar = self.grammar;
|
||||
std::string scope = to_s((NSString*)[grammar objectForKey:@"scope"]);
|
||||
oak::uuid_t uuid = to_s((NSString*)[grammar objectForKey:@"uuid"]);
|
||||
oak::uuid_t bundleUUID = to_s((NSString*)[grammar objectForKey:@"bundleUUID"]);
|
||||
std::string scope = to_s([grammar objectForKey:@"scope"]);
|
||||
oak::uuid_t uuid = to_s([grammar objectForKey:@"uuid"]);
|
||||
oak::uuid_t bundleUUID = to_s([grammar objectForKey:@"bundleUUID"]);
|
||||
|
||||
if(is_installed(uuid))
|
||||
{
|
||||
|
||||
@@ -568,7 +568,7 @@ static NSButton* OakCreateStopSearchButton ()
|
||||
{
|
||||
std::vector<std::string> paths;
|
||||
for(NSUInteger i = 0; i < [self.recentFolders count]; ++i)
|
||||
paths.push_back(to_s((NSString*)[self.recentFolders objectAtIndex:i]));
|
||||
paths.push_back(to_s([self.recentFolders objectAtIndex:i]));
|
||||
if(NSString* folder = self.searchFolder)
|
||||
paths.push_back(to_s(folder));
|
||||
paths.push_back(to_s(self.projectFolder));
|
||||
|
||||
@@ -99,7 +99,7 @@ OAK_DEBUG_VAR(HTMLOutput_JSBridge);
|
||||
if([options isKindOfClass:[NSNumber class]])
|
||||
range = text::pos_t([options intValue]-1, 0);
|
||||
else if([options isKindOfClass:[NSString class]])
|
||||
range = to_s((NSString*)options);
|
||||
range = to_s(options);
|
||||
document::show(document::create(to_s(path)), document::kCollectionAny, range);
|
||||
}
|
||||
|
||||
|
||||
@@ -830,12 +830,12 @@ static NSMutableSet* SymmetricDifference (NSMutableSet* aSet, NSMutableSet* anot
|
||||
|
||||
- (void)executeBundleCommand:(id)sender
|
||||
{
|
||||
if(bundles::item_ptr item = bundles::lookup(to_s((NSString*)[sender representedObject])))
|
||||
if(bundles::item_ptr item = bundles::lookup(to_s([sender representedObject])))
|
||||
{
|
||||
std::map<std::string, std::string> map = oak::basic_environment();
|
||||
map << [self variables] << item->bundle_variables();
|
||||
map = bundles::scope_variables(map);
|
||||
map = variables_for_path(map, to_s((NSString*)[self.selectedPaths firstObject]));
|
||||
map = variables_for_path(map, to_s([self.selectedPaths firstObject]));
|
||||
document::run(parse_command(item), ng::buffer_t(), ng::ranges_t(), [self.selectedPaths count] == 1 ? document::create(map["TM_SELECTED_FILE"]) : document::document_ptr(), map);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -758,8 +758,8 @@ static std::vector<bundles::item_ptr> relevant_items_in_scope (scope::context_t
|
||||
for(NSDictionary* item in items)
|
||||
{
|
||||
std::vector<std::pair<size_t, size_t>> cover_path, cover_name;
|
||||
std::string name = to_s((NSString*)item[@"name"]);
|
||||
std::string path = to_s((NSString*)item[@"path"]);
|
||||
std::string name = to_s(item[@"name"]);
|
||||
std::string path = to_s(item[@"path"]);
|
||||
|
||||
double rank = (items.count - rankedItems.size()) / (double)items.count;
|
||||
if(OakNotEmptyString(filter))
|
||||
@@ -872,7 +872,7 @@ static std::vector<bundles::item_ptr> relevant_items_in_scope (scope::context_t
|
||||
- (BOOL)canAccept
|
||||
{
|
||||
NSDictionary* item = self.tableView.selectedRow != -1 ? self.items[self.tableView.selectedRow] : nil;
|
||||
return item[@"menuItem"] || item[@"action"] || item[@"uuid"] && bundles::lookup(to_s((NSString*)item[@"uuid"]))->kind() != bundles::kItemTypeSettings;
|
||||
return item[@"menuItem"] || item[@"action"] || item[@"uuid"] && bundles::lookup(to_s(item[@"uuid"]))->kind() != bundles::kItemTypeSettings;
|
||||
}
|
||||
|
||||
- (BOOL)canEdit
|
||||
|
||||
@@ -563,7 +563,7 @@ private:
|
||||
|
||||
- (void)takeGrammarUUIDFrom:(id)sender
|
||||
{
|
||||
if(bundles::item_ptr item = bundles::lookup(to_s((NSString*)[sender representedObject])))
|
||||
if(bundles::item_ptr item = bundles::lookup(to_s([sender representedObject])))
|
||||
[textView performBundleItem:item];
|
||||
}
|
||||
|
||||
|
||||
@@ -1277,10 +1277,10 @@ doScroll:
|
||||
if(false) {
|
||||
} else if([attribute isEqualToString:NSAccessibilityValueAttribute]) {
|
||||
AUTO_REFRESH;
|
||||
document->set_content(to_s((NSString*)value));
|
||||
document->set_content(to_s(value));
|
||||
} else if([attribute isEqualToString:NSAccessibilitySelectedTextAttribute]) {
|
||||
AUTO_REFRESH;
|
||||
editor->insert(to_s((NSString*)value));
|
||||
editor->insert(to_s(value));
|
||||
} else if([attribute isEqualToString:NSAccessibilitySelectedTextRangeAttribute]) {
|
||||
[self accessibilitySetValue:@[ value ] forAttribute:NSAccessibilitySelectedTextRangesAttribute];
|
||||
} else if([attribute isEqualToString:NSAccessibilitySelectedTextRangesAttribute]) {
|
||||
@@ -2175,7 +2175,7 @@ static void update_menu_key_equivalents (NSMenu* menu, std::multimap<std::string
|
||||
{
|
||||
D(DBF_OakTextView_Spelling, bug("%s\n", [[menuItem representedObject] UTF8String]););
|
||||
AUTO_REFRESH;
|
||||
editor->insert(to_s((NSString*)[menuItem representedObject]));
|
||||
editor->insert(to_s([menuItem representedObject]));
|
||||
if([NSSpellChecker sharedSpellCheckerExists])
|
||||
[[NSSpellChecker sharedSpellChecker] updateSpellingPanelWithMisspelledWord:[menuItem representedObject]];
|
||||
}
|
||||
@@ -2286,7 +2286,7 @@ static void update_menu_key_equivalents (NSMenu* menu, std::multimap<std::string
|
||||
{
|
||||
std::map<std::string, std::string> variables;
|
||||
for(NSString* key in [captures allKeys])
|
||||
variables.emplace(to_s(key), to_s((NSString*)captures[key]));
|
||||
variables.emplace(to_s(key), to_s(captures[key]));
|
||||
replacement = format_string::expand(replacement, variables);
|
||||
}
|
||||
editor->insert(replacement, true);
|
||||
@@ -3084,7 +3084,7 @@ static char const* kOakMenuItemTitle = "OakMenuItemTitle";
|
||||
{
|
||||
oak::uuid_t projectIdentifier = document::kCollectionAny;
|
||||
if([self.window.delegate respondsToSelector:@selector(identifier)]) // FIXME This should be a formal interface
|
||||
projectIdentifier = to_s((NSString*)[self.window.delegate performSelector:@selector(identifier)]);
|
||||
projectIdentifier = to_s([self.window.delegate performSelector:@selector(identifier)]);
|
||||
|
||||
document::show(document::from_content(output, document->file_type()), projectIdentifier);
|
||||
}
|
||||
|
||||
@@ -32,12 +32,12 @@
|
||||
|
||||
- (void)selectNewFileType:(NSMenuItem*)sender
|
||||
{
|
||||
settings_t::set(kSettingsFileTypeKey, to_s((NSString*)[sender representedObject]), "attr.untitled");
|
||||
settings_t::set(kSettingsFileTypeKey, to_s([sender representedObject]), "attr.untitled");
|
||||
}
|
||||
|
||||
- (void)selectUnknownFileType:(NSMenuItem*)sender
|
||||
{
|
||||
settings_t::set(kSettingsFileTypeKey, to_s((NSString*)[sender representedObject]), "attr.file.unknown-type");
|
||||
settings_t::set(kSettingsFileTypeKey, to_s([sender representedObject]), "attr.file.unknown-type");
|
||||
}
|
||||
|
||||
- (void)loadView
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
{
|
||||
newValue = newValue ?: @"";
|
||||
if([newValue isKindOfClass:[NSString class]])
|
||||
return settings_t::set(to_s(key), to_s((NSString*)newValue));
|
||||
return settings_t::set(to_s(key), to_s(newValue));
|
||||
NSLog(@"%s wrong type for %@: ‘%@’", sel_getName(_cmd), aKey, newValue);
|
||||
}
|
||||
[super setValue:newValue forUndefinedKey:aKey];
|
||||
|
||||
Reference in New Issue
Block a user