• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSXML and invalid UTF8 characters
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSXML and invalid UTF8 characters


  • Subject: Re: NSXML and invalid UTF8 characters
  • From: Keith Blount <email@hidden>
  • Date: Fri, 29 Jan 2010 11:16:32 -0800 (PST)

Hi Jens,

Thanks again.

> Variable names shouldn't start with an uppercase letter —
> the convention is to lowercase the entire acronym that
> starts a name, so "xmlCharacterSet".

I'm aware of that and it's not a habit I'm generally in - a year ago I would always have used "xmlCharacterSet" rather than "XMLCharacterSet", but of late I've been picking up bad habits from the AppKit itself, based on accessor methods (which generally follow the same naming conventions as variables) beginning with initials. :) For instance, -(PDFDocument *)PDFDocument rather than - (PDFDocument *)pdfDocument, and -(NSURL *)URL rather than -(NSURL *)url. So I've recently picked up the habit of using uppercase for "PDF", "XML" etc by osmosis.

>
> >         range =
> [cleanedString
> rangeOfCharacterFromSet:invalidXMLCharacterSet];
>
> FYI: If you ever find this method is a performance
> bottleneck, you can make it run faster on long strings by
> using the variant of this method that takes a range, and
> passing in the range from the last deletion point to the end
> of the string. That will avoid scanning the already-cleaned
> prefix again.

-rangeOfCharactersFromSet:options:range: - makes sense, and will do! Thanks.

>
> >     return (NSString *)[cleanedString
> autorelease];
>
> The cast isn't necessary; an NSMutableString is an
> NSString.

A habit from my fear that the compiler will get even fussier (for instance it is these days fussier about conditional expressions).

> I find it more maintainable to do the autorelease at the
> same time I create the object.

I do the same in long methods for the same reason, but in very short methods like this one, where the object is created before a loop and then returned immediately afterwards, I often autorelease it at the end. Point taken though!

Thanks again and all the best,
Keith


--- On Fri, 1/29/10, Jens Alfke <email@hidden> wrote:

> From: Jens Alfke <email@hidden>
> Subject: Re: NSXML and invalid UTF8 characters
> To: "Keith Blount" <email@hidden>
> Cc: email@hidden
> Date: Friday, January 29, 2010, 5:05 PM
> This code looks good. Just a few
> possible improvements, in the spirit of code-review:
>
> On Jan 29, 2010, at 4:00 AM, Keith Blount wrote:
>
> >        
> NSMutableCharacterSet *XMLCharacterSet =
> [[NSMutableCharacterSet alloc] init];
>
> Variable names shouldn't start with an uppercase letter —
> the convention is to lowercase the entire acronym that
> starts a name, so "xmlCharacterSet".
>
> >         range =
> [cleanedString
> rangeOfCharacterFromSet:invalidXMLCharacterSet];
>
> FYI: If you ever find this method is a performance
> bottleneck, you can make it run faster on long strings by
> using the variant of this method that takes a range, and
> passing in the range from the last deletion point to the end
> of the string. That will avoid scanning the already-cleaned
> prefix again.
>
> >     return (NSString *)[cleanedString
> autorelease];
>
> The cast isn't necessary; an NSMutableString is an
> NSString.
>
> I find it more maintainable to do the autorelease at the
> same time I create the object, i.e. change the declaration
> to
>     NSMutableString *cleanedString = [[self
> mutableCopy] autorelease];
> and then just "return cleanedString" at the end. That way
> if you (or someone else) every modifies the code later to
> add an earlier 'return' statement, they won't accidentally
> create a memory leak if they forget to autorelease it.
>
> —Jens



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: NSXML and invalid UTF8 characters
      • From: Jens Alfke <email@hidden>
References: 
 >Re: NSXML and invalid UTF8 characters (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: Network Reachability
  • Next by Date: Re: determining HTML text encoding
  • Previous by thread: Re: NSXML and invalid UTF8 characters
  • Next by thread: Re: NSXML and invalid UTF8 characters
  • Index(es):
    • Date
    • Thread