Re: ARC question

2012-10-31 Thread BobCromwell
Every assignment will release the old one,so no leak.

From My iPhone

在 2012-10-29,下午7:34,Mike Abdullah  写道:

> 
> On 29 Oct 2012, at 10:06, Vincent Habchi  wrote:
> 
>> Hi folks,
>> 
>> before aught else, all my thoughts to those of you in the Eastern coast that 
>> are preparing themselves for a bunch of bleak days…
>> 
>> I’ve just a silly question (I know, I don’t post very often and I apologize 
>> for that): I need to convert a HTML style string, with “& escapes” to normal 
>> UTF-8. So I wrote this:
>> 
>> -(NSString *)convertHTMLtoUTF8:(NSString *)aString {
>>
>>NSString * convertedString = [aString copy];
>>for (NSString * pattern in [HTMLtoUTF keyEnumerator]) {
>>convertedString = [convertedString 
>> stringByReplacingOccurrencesOfString:pattern 
>> withString:HTMLtoUTF [pattern]];
>>}
>>
>>return convertedString;
>> }
>> 
>> where HTMLtoUTF is a dictionary of pairs {@"&…;" : 
>> @""}.
>> 
>> Now, my question is: is that scheme going to work correctly with ARC? Is it 
>> not going to leak each intermediate version of ‘convertedString’?
> 
> The code is a fairly inefficient to start with, but no, it's not going to 
> leak.
> 
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/bob.cromwell2012%40gmail.com
> 
> This email sent to bob.cromwell2...@gmail.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: ARC question

2012-10-29 Thread Vincent Habchi
Mike:

> How are those accented characters represented in your HTML?

Thanks for pointing this. It turns out, after examination, that the accented 
chars are already provided in UTF-8, and that only & and ' need to be 
translated. Strange. I was sure I saw other escapes around on some contents 
before.

Anyhow, thanks again for your help.
Vincent



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: ARC question

2012-10-29 Thread Mike Abdullah

On 29 Oct 2012, at 13:55, Vincent Habchi wrote:

> Le 29 oct. 2012 à 14:34, Mike Abdullah  a écrit :
> 
>> Well, you can ask CFXMLCreateStringByUnescapingEntities() to do this on OS 
>> X, although if I recall all the CFXML functions have now sadly been 
>> deprecated. The source code for it should still be available if you search 
>> around.
> 
> I wasn’t aware of those calls. They do not seem to be deprecated. However, I 
> have also a lot of accented characters (é, à, û, etc.) to unescape (since the 
> contents are in French), and CFXMLCreateStringByUnescapingEntities() provides 
> a basic dictionary of only five elements; it is extensible, but of course at 
> the expense of creating a custom dictionary, which, added to the necessary 
> conversions between CFStringRef and NSString and vice-versa, would hamper the 
> legibility of the code somewhat.

How are those accented characters represented in your HTML?
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: ARC question

2012-10-29 Thread Vincent Habchi
> That’s blatant. […]

I meant obvious. I just read the use of “blatant” for “obvious” was incorrect. 
My bad.

Vincent
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: ARC question

2012-10-29 Thread Vincent Habchi
Le 29 oct. 2012 à 15:30, glenn andreas  a écrit :

> Given that there are also decimal (&#DD;) and hexadecimal escape sequences 
> (&#x;) in HTML, trying to support those through the use of a dictionary 
> of sequence -> replacement is going to be impractical.

Hopefully, I have only to address a tiny subset of these.

> Scanning through the string to find & and test for valid escape sequences 
> (including both the 250 or so named entities plus those numeric escape 
> sequences) is the right way to go, since the time spent on the string is 
> dependent on the number of escape sequences in the string, not the number of 
> possible escape sequences.

That’s blatant. I wonder why Apple never added a method in Cocoa to perform 
this task. Is there anything close in WebKit?

V.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: ARC question

2012-10-29 Thread glenn andreas

On Oct 29, 2012, at 8:34 AM, Mike Abdullah  wrote:

> 
> On 29 Oct 2012, at 11:44, Vincent Habchi  wrote:
> 
>> Le 29 oct. 2012 à 12:34, Mike Abdullah  a écrit :
>> 
>>> The code is a fairly inefficient to start with, but no, it's not going to 
>>> leak.
>> 
>> Thanks. I am aware of this, but since this code is going to be part of a 
>> didactic article on writing a WMS client, I emphasize clarity over 
>> performance (this is a secondary aspect).
>> 
>> However, I am interested in knowing how you would write such a translator 
>> yourself to make it more efficient. I had initially the idea of copying 
>> every char until a ‘&’, in which case the following content would be 
>> analyzed and replaced if necessary, and so on until the end of the HTML 
>> string. That would mean one single pass instead of as many as the number of 
>> pairs in the dictionary. 
> 
> Well, you can ask CFXMLCreateStringByUnescapingEntities() to do this on OS X, 
> although if I recall all the CFXML functions have now sadly been deprecated. 
> The source code for it should still be available if you search around.
> 
> But in general, I would just work my way through the string looking for 
> occurrences of '&' and see if that makes up a valid escape sequence. Much of 
> the problem if dealing with HTML rather than XML is that there are a vast 
> range of special sequences. e.g. µ
> 


Given that there are also decimal (&#DD;) and hexadecimal escape sequences 
(&#x;) in HTML, trying to support those through the use of a dictionary of 
sequence -> replacement is going to be impractical.

Scanning through the string to find & and test for valid escape sequences 
(including both the 250 or so named entities plus those numeric escape 
sequences) is the right way to go, since the time spent on the string is 
dependent on the number of escape sequences in the string, not the number of 
possible escape sequences.





Glenn Andreas  gandr...@gandreas.com 
  wicked fun!
Mad, Bad, and Dangerous to Know


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: ARC question

2012-10-29 Thread Vincent Habchi
Le 29 oct. 2012 à 15:00, Kyle Sluder  a écrit :

> On Oct 29, 2012, at 6:55 AM, Vincent Habchi  wrote:
> 
> Actually, it's not. From the docs:
> 
>> Note: Currently, only the standard predefined entities are supported; 
>> passing NULL for entitiesDictionary is sufficient. 
> 
> This kind of thing is why CFXML is deprecated.

Oh, I understood one could supply his/her own dictionary or NULL if the 
standard one was sufficient. Thanks for pointing this out: It makes the comment 
I was planning to add pointless.

But where did you get that these calls were deprecated (apart from insider 
lore)? I see no such warning in the docs.

> I haven't tried it myself, but maybe you can construct an NSXMLDTD that 
> references the standard HTML DTD and query it for entity expansions?

Kyle, with all due respects, that maybe a fine idea, but it lies way beyond my 
own knowledge of the XML syntax! I even hardly know what a ‘DTD’ is about… ;) 
Would it be more efficient than a ‘brute force’ substitution algorithm like the 
one Mike suggested?

Thanks a bunch,
Vincent
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: ARC question

2012-10-29 Thread Kyle Sluder
On Oct 29, 2012, at 6:55 AM, Vincent Habchi  wrote:

> Le 29 oct. 2012 à 14:34, Mike Abdullah  a écrit :
> 
>> Well, you can ask CFXMLCreateStringByUnescapingEntities() to do this on OS 
>> X, although if I recall all the CFXML functions have now sadly been 
>> deprecated. The source code for it should still be available if you search 
>> around.
> 
> I wasn’t aware of those calls. They do not seem to be deprecated. However, I 
> have also a lot of accented characters (é, à, û, etc.) to unescape (since the 
> contents are in French), and CFXMLCreateStringByUnescapingEntities() provides 
> a basic dictionary of only five elements; it is extensible, but of course at 
> the expense of creating a custom dictionary,

Actually, it's not. From the docs:

> Note: Currently, only the standard predefined entities are supported; passing 
> NULL for entitiesDictionary is sufficient. 
> 
This kind of thing is why CFXML is deprecated.

> 
>> But in general, I would just work my way through the string looking for 
>> occurrences of '&' and see if that makes up a valid escape sequence. Much of 
>> the problem if dealing with HTML rather than XML is that there are a vast 
>> range of special sequences. e.g. µ
> 
> Yeah, that’s what I thought of. I will add a note in the body of the article 
> about this.

I haven't tried it myself, but maybe you can construct an NSXMLDTD that 
references the standard HTML DTD and query it for entity expansions?

--Kyle Sluder
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: ARC question

2012-10-29 Thread Vincent Habchi
Le 29 oct. 2012 à 14:34, Mike Abdullah  a écrit :

> Well, you can ask CFXMLCreateStringByUnescapingEntities() to do this on OS X, 
> although if I recall all the CFXML functions have now sadly been deprecated. 
> The source code for it should still be available if you search around.

I wasn’t aware of those calls. They do not seem to be deprecated. However, I 
have also a lot of accented characters (é, à, û, etc.) to unescape (since the 
contents are in French), and CFXMLCreateStringByUnescapingEntities() provides a 
basic dictionary of only five elements; it is extensible, but of course at the 
expense of creating a custom dictionary, which, added to the necessary 
conversions between CFStringRef and NSString and vice-versa, would hamper the 
legibility of the code somewhat.

> But in general, I would just work my way through the string looking for 
> occurrences of '&' and see if that makes up a valid escape sequence. Much of 
> the problem if dealing with HTML rather than XML is that there are a vast 
> range of special sequences. e.g. µ

Yeah, that’s what I thought of. I will add a note in the body of the article 
about this.

Thanks for all!
Vincent


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: ARC question

2012-10-29 Thread Mike Abdullah

On 29 Oct 2012, at 11:44, Vincent Habchi  wrote:

> Le 29 oct. 2012 à 12:34, Mike Abdullah  a écrit :
> 
>> The code is a fairly inefficient to start with, but no, it's not going to 
>> leak.
> 
> Thanks. I am aware of this, but since this code is going to be part of a 
> didactic article on writing a WMS client, I emphasize clarity over 
> performance (this is a secondary aspect).
> 
> However, I am interested in knowing how you would write such a translator 
> yourself to make it more efficient. I had initially the idea of copying every 
> char until a ‘&’, in which case the following content would be analyzed and 
> replaced if necessary, and so on until the end of the HTML string. That would 
> mean one single pass instead of as many as the number of pairs in the 
> dictionary. 

Well, you can ask CFXMLCreateStringByUnescapingEntities() to do this on OS X, 
although if I recall all the CFXML functions have now sadly been deprecated. 
The source code for it should still be available if you search around.

But in general, I would just work my way through the string looking for 
occurrences of '&' and see if that makes up a valid escape sequence. Much of 
the problem if dealing with HTML rather than XML is that there are a vast range 
of special sequences. e.g. µ


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: ARC question

2012-10-29 Thread Mike Abdullah

On 29 Oct 2012, at 12:01, Vincent Habchi  wrote:

> Le 29 oct. 2012 à 12:53, Roland King  a écrit :
> 
>> Does CFURLCreateStringByReplacingPercentEscapes() not do this for you? I 
>> often use it going the other way from text to escaped text, not just for 
>> URLs. 
> 
> AFAIK, CFURLCreateStringByReplacingPercentEscapes() substitues special chars 
> for % in URLs (e.g: “ ” ↔ “%20”) but does not handle HTML-ampersand escapes 
> (e.g:   ↔ “ ”). I did a shallow Google search and found nothing except 
> statements that no NSString or other Cocoa object could provide such a 
> service.

Indeed, CFURLCreateStringByReplacingPercentEscapes and friends deal in 
*percent* escaping, not *XML entity* escaping
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: ARC question

2012-10-29 Thread Vincent Habchi
Le 29 oct. 2012 à 12:53, Roland King  a écrit :

> Does CFURLCreateStringByReplacingPercentEscapes() not do this for you? I 
> often use it going the other way from text to escaped text, not just for 
> URLs. 

AFAIK, CFURLCreateStringByReplacingPercentEscapes() substitues special chars 
for % in URLs (e.g: “ ” ↔ “%20”) but does not handle HTML-ampersand escapes 
(e.g:   ↔ “ ”). I did a shallow Google search and found nothing except 
statements that no NSString or other Cocoa object could provide such a service.

Vincent
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: ARC question

2012-10-29 Thread Roland King

On 29 Oct, 2012, at 7:44 PM, Vincent Habchi  wrote:

> Le 29 oct. 2012 à 12:34, Mike Abdullah  a écrit :
> 
>> The code is a fairly inefficient to start with, but no, it's not going to 
>> leak.
> 
> Thanks. I am aware of this, but since this code is going to be part of a 
> didactic article on writing a WMS client, I emphasize clarity over 
> performance (this is a secondary aspect).
> 
> However, I am interested in knowing how you would write such a translator 
> yourself to make it more efficient. I had initially the idea of copying every 
> char until a ‘&’, in which case the following content would be analyzed and 
> replaced if necessary, and so on until the end of the HTML string. That would 
> mean one single pass instead of as many as the number of pairs in the 
> dictionary. 
> 
> Vincent
> 

Does CFURLCreateStringByReplacingPercentEscapes() not do this for you? I often 
use it going the other way from text to escaped text, not just for URLs. 
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: ARC question

2012-10-29 Thread Vincent Habchi
Le 29 oct. 2012 à 12:34, Mike Abdullah  a écrit :

> The code is a fairly inefficient to start with, but no, it's not going to 
> leak.

Thanks. I am aware of this, but since this code is going to be part of a 
didactic article on writing a WMS client, I emphasize clarity over performance 
(this is a secondary aspect).

However, I am interested in knowing how you would write such a translator 
yourself to make it more efficient. I had initially the idea of copying every 
char until a ‘&’, in which case the following content would be analyzed and 
replaced if necessary, and so on until the end of the HTML string. That would 
mean one single pass instead of as many as the number of pairs in the 
dictionary. 

Vincent


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: ARC question

2012-10-29 Thread Mike Abdullah

On 29 Oct 2012, at 10:06, Vincent Habchi  wrote:

> Hi folks,
> 
> before aught else, all my thoughts to those of you in the Eastern coast that 
> are preparing themselves for a bunch of bleak days…
> 
> I’ve just a silly question (I know, I don’t post very often and I apologize 
> for that): I need to convert a HTML style string, with “& escapes” to normal 
> UTF-8. So I wrote this:
> 
> -(NSString *)convertHTMLtoUTF8:(NSString *)aString {
>   
>   NSString * convertedString = [aString copy];
>   for (NSString * pattern in [HTMLtoUTF keyEnumerator]) {
>   convertedString = [convertedString 
> stringByReplacingOccurrencesOfString:pattern 
>
> withString:HTMLtoUTF [pattern]];
>   }
>   
>   return convertedString;
> }
> 
> where HTMLtoUTF is a dictionary of pairs {@"&…;" : 
> @""}.
> 
> Now, my question is: is that scheme going to work correctly with ARC? Is it 
> not going to leak each intermediate version of ‘convertedString’?

The code is a fairly inefficient to start with, but no, it's not going to leak.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com