In article <0amdnR0QzLH3XsPVnZ2dnUVZ_iydnZ2d@[EMAIL PROTECTED]
>,
Don Bruder <dakidd@[EMAIL PROTECTED]
> wrote:
> Humor my OCD :)
>
> I have a method (as part of a category adding on to NSMutableData) I'm
> trying to name in a "by the conventions" fa****on. It works fine -
> nothing wrong there. I just don't like the way the method declaration,
> or calls to it, look - it seems "klunky". So I wonder how other folks
> would name it to make it more "elegant".
>
> As an NSMutableData object loaded with arbitrary data, it needs to hunt
> for two "magic strings" within itself, grab the data between those two
> "magic strings", turn it into an NSString, and hand it back to the
> caller. The "magic strings" might be practically any length, and it's
> typical that they wont have any resemblance to each other - For
> instance, the first one might be "Magic String 1 ", and the second might
> be " Blow It Out Your Ear". Given that, and the (admittedly contrived)
> block of data that follows, I need the NSString that comes back from an
> invocation of the method to be "This Is The Part I Want":
>
> The data block:
> This is just some random garbage that I'm typing as an example Magic
> String 1 This Is The Part I Want Blow It Out Your Ear and more data
> follows that may or may not be related
>
> For the moment, I've got the method coded like so:
>
> // MyNSMutableExtensions.h
> // elide boilerplate #im****ts and other irrelevancies to save space
> @[EMAIL PROTECTED]
NSMutableData (MyExtensions)
> - (NSString *)GetStringDelimitedBy:(NSString *)Delim1
> EndingWith:(NSString *)Delim2;
> // elide more irrelevancies
> @[EMAIL PROTECTED]
>
> So assuming "TheObject" is an NSMutableData object holding (at least...)
> the data block shown above, the following code hands me back "This Is
> The Part I Want" in Result - exactly as I want it to:
>
> NSString *Result;
> NSString *MS1 = @[EMAIL PROTECTED]
"Magic String 1 ";
> NSString *MS2 = @[EMAIL PROTECTED]
" Blow It Out Your Ear"
>
> Result = [TheObject getStringDelimitedBy:MS1 endingWith:MS2];
>
> Like I said, it WORKS fine. But my personal sense of style says it
> *LOOKS LIKE* complete crap.
>
> How would *YOU* name such a method?
- (NSString*)substringBetween:(NSString*)inStartDelimiter
and:(NSString*)inEndDelimiter
{
}
That's just off the top of my head. It's got room for improvement, but
I'm fairly certain I'd start with 'substring'. Objective-C methods that
start with 'get' are rare and from a quick survey appear to have the
behavior of filling a provided buffer.
For what it's worth, I'd make it a category on NSData. There's nothing
about such a method that should require mutability.
G
--
"Harry?" Ron's voice was a mere whisper. "Do you smell something ...
burning?"
- Harry Potter and the Odor of the Phoenix


|