如何在 Xcode 4 的 GDB 输出窗口中显示 Invisibles?

发布于 2024-11-06 07:28:58 字数 210 浏览 0 评论 0原文

我刚刚发现由于字符串长度不匹配而导致的字符串相等错误。额外的字符是“\r”,它根本不会显示在 Xcode 4 的输出窗口中。如果确实如此,我就不必花费那么多时间来追踪问题。

是否可以在输出窗口中显示空白字符?如果可以的话,我要念什么咒语才能实现呢?

我尝试在编辑器菜单下显示不可见内容,但这仅适用于代码编辑器,不适用于输出窗口。我在 iOS 应用程序上使用 Xcode 4。

I just tracked down a string equality bug due to string length mismatch. The extra character was '\r' which doesn't show up in the output window in Xcode 4 at all. If it had, I wouldn't have to spend nearly as much time as I did tracking the issue down.

Is it possible to show whitespace characters in the output window? If so, what magic incantation must I recite to enable it?

I tried Show Invisibles under the Editor menu, but that only worked for the code editors, not the output window. I'm using Xcode 4 on an iOS app.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

脱离于你 2024-11-13 07:28:58

我现在只能想到一种解决方案:创建一个类别:

NSString+myAdditions.h

@interface NSString (myAdditions) 

- (NSString *)showInvisibles;

@end

NSString+myAdditions.m

#import "NSString+myAdditions.h"

@implementation NSString (myAdditions)

- (NSString *)showInvisibles
{
    NSString *regexToReplaceWhitespaces = @"([\\s])";   

    NSError *error = NULL;
    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regexToReplaceWhitespaces
                                                                           options:NSRegularExpressionCaseInsensitive
                                                                             error:&error];

    NSString *result = [regex stringByReplacingMatchesInString:self
                                                       options:0
                                                         range:NSMakeRange(0, [self length])
                                                  withTemplate:@"␣"];

    return result;
}

@end

用法

NSLog(@"show me the unseen: %@", [@"soo      many    whitespace in here  \t\t <- look two tabs!" showInvisibles]);

输出

soo␣␣␣␣␣␣many␣␣␣␣whitespace␣in␣here␣␣␣␣␣<-␣look␣two␣tabs!

I can think of only one solution right now: Creating a category:

NSString+myAdditions.h

@interface NSString (myAdditions) 

- (NSString *)showInvisibles;

@end

NSString+myAdditions.m

#import "NSString+myAdditions.h"

@implementation NSString (myAdditions)

- (NSString *)showInvisibles
{
    NSString *regexToReplaceWhitespaces = @"([\\s])";   

    NSError *error = NULL;
    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regexToReplaceWhitespaces
                                                                           options:NSRegularExpressionCaseInsensitive
                                                                             error:&error];

    NSString *result = [regex stringByReplacingMatchesInString:self
                                                       options:0
                                                         range:NSMakeRange(0, [self length])
                                                  withTemplate:@"␣"];

    return result;
}

@end

Usage

NSLog(@"show me the unseen: %@", [@"soo      many    whitespace in here  \t\t <- look two tabs!" showInvisibles]);

Output

soo␣␣␣␣␣␣many␣␣␣␣whitespace␣in␣here␣␣␣␣␣<-␣look␣two␣tabs!
鹿! 2024-11-13 07:28:58

您可以对字符串进行百分比转义。您可以在第三个参数中指定哪些字符转义(我包括了所有常见的字符),其余字符将被转义:

NSLog(@"%@", CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)yourString, (CFStringRef)@" <>#%{}|\^~[]`;/?:@=&$", NULL, kCFStringEncodingUTF8);

You could percent-escape your string. You can specify which characters to not escape in the third parameter (I included all of the common ones), the rest of which will be escaped:

NSLog(@"%@", CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)yourString, (CFStringRef)@" <>#%{}|\^~[]`;/?:@=&$", NULL, kCFStringEncodingUTF8);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文