Re: [NSMutableData resetDataRangeTo:(NSRange)range];

2014-07-15 Thread Kyle Sluder
On Jul 15, 2014, at 10:20 AM, Jens Alfke wrote: > > >> On Jul 15, 2014, at 9:50 AM, Carl Hoefs >> wrote: >> >> Awesome! I had been wondering if this concept existed in Cocoa, didn't see >> it in the NSData docs. It's sort of like using iovec structs with >> readv/writev for sockets. I would

Re: [NSMutableData resetDataRangeTo:(NSRange)range];

2014-07-15 Thread Jens Alfke
On Jul 15, 2014, at 9:50 AM, Carl Hoefs wrote: > Awesome! I had been wondering if this concept existed in Cocoa, didn't see it > in the NSData docs. It's sort of like using iovec structs with readv/writev > for sockets. I would primarily use the dispatch_data_create_map() function, > right? L

Re: [NSMutableData resetDataRangeTo:(NSRange)range];

2014-07-15 Thread Carl Hoefs
On Jul 15, 2014, at 1:45 AM, Mike Abdullah wrote: > > Another possibility is to use dispatch_data. Rather than copy bytes around to > assemble them into a contiguous buffer, your use case might be just as well > suited to dispatch_data’s approach of tying together various non-contiguous > buff

Re: [NSMutableData resetDataRangeTo:(NSRange)range];

2014-07-15 Thread Mike Abdullah
On 15 Jul 2014, at 00:32, Jens Alfke wrote: > > On Jul 14, 2014, at 1:07 PM, Carl Hoefs > wrote: > >>modifiableData = [ NSMutableData dataWithData: [ external call that gives >> me an NSData ] ]; > > It’s shorter and more idiomatic to just say > modifiableData = [external mutable

Re: [NSMutableData resetDataRangeTo:(NSRange)range];

2014-07-14 Thread Graham Cox
On 15 Jul 2014, at 4:54 am, Jens Alfke wrote: > The equivalent function in the ‘classic’ Mac OS had the very appropriate name > of Munger( ) since it would munge bytes around in a heap block. Knowing how > to use Munger was a sign of geek cred in the old (80s-90s) Mac dev community. My god,

Re: [NSMutableData resetDataRangeTo:(NSRange)range];

2014-07-14 Thread Jens Alfke
On Jul 14, 2014, at 1:07 PM, Carl Hoefs wrote: > modifiableData = [ NSMutableData dataWithData: [ external call that gives > me an NSData ] ]; It’s shorter and more idiomatic to just say modifiableData = [external mutableCopy]; (plus an autorelease if you’re not using ARC) > Will

Re: [NSMutableData resetDataRangeTo:(NSRange)range];

2014-07-14 Thread Carl Hoefs
On Jul 14, 2014, at 12:57 PM, "Gary L. Wade" wrote: > where you're creating the object On Jul 14, 2014, at 12:53 PM, Jens Alfke wrote: > If you’re the one creating the NSData object in the first place, can you > create it as an NSMutableData? Certainly that makes sense enough, just hoping

Re: [NSMutableData resetDataRangeTo:(NSRange)range];

2014-07-14 Thread Gary L. Wade
The reason you can't do exactly what you're asking is because there may be other owners of the immutable object. Since NSMutableData is a subclass of NSData, you should ask yourself where you're creating the object and try creating it from the start as mutable, and also if there are owners of th

Re: [NSMutableData resetDataRangeTo:(NSRange)range];

2014-07-14 Thread Jens Alfke
On Jul 14, 2014, at 12:15 PM, Carl Hoefs wrote: > Okay, 1 last question on this. Is there a way to promote-in-place an NSData > object into an NSMutableData object? -becomeMutable or some such? I'm trying > to avoid copying megabytes of data/sec if it's avoidable. Nope. Part of the contract

Re: [NSMutableData resetDataRangeTo:(NSRange)range];

2014-07-14 Thread Carl Hoefs
in my mind that >> the one couldn't do the other. But that's the whole purpose of the NSRange. >> Very cool. > > The equivalent function in the ‘classic’ Mac OS had the very appropriate name > of Munger( ) since it would munge bytes around in a heap block. Knowing how

Re: [NSMutableData resetDataRangeTo:(NSRange)range];

2014-07-14 Thread Jens Alfke
On Jul 14, 2014, at 11:48 AM, Carl Hoefs wrote: > Yes, I guess it's the semantics that threw me. I was attempting to > "insertBytesInRange" not "replaceBytesInRange", so I had it in my mind that > the one couldn't do the other. But that's the whol

Re: [NSMutableData resetDataRangeTo:(NSRange)range];

2014-07-14 Thread Carl Hoefs
ot; not "replaceBytesInRange", so I had it in my mind that the one couldn't do the other. But that's the whole purpose of the NSRange. Very cool. -Carl ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin

Re: [NSMutableData resetDataRangeTo:(NSRange)range];

2014-07-14 Thread Ben Kennedy
On 14 Jul 2014, at 11:30 am, Carl Hoefs wrote: >> [bigMData replaceBytesInRange:NSMakeRange(0,0) withBytes:newBytesPtr >> length:1024]; > > Wow, that's damn clever! My thinking is so clunky. It never would have > occurred to me that NSMutableData could expand (0,0) into (0,1024) out of > thin

Re: [NSMutableData resetDataRangeTo:(NSRange)range];

2014-07-14 Thread Carl Hoefs
On Jul 14, 2014, at 11:22 AM, Mike Abdullah wrote: > [bigMData replaceBytesInRange:NSMakeRange(0,0) >withBytes:newBytesPtr > length:1024]; On Jul 14, 2014, at 11:23 AM, Ben Kennedy wrote: > [bigMData replaceBytesInRan

Re: [NSMutableData resetDataRangeTo:(NSRange)range];

2014-07-14 Thread Ben Kennedy
On 14 Jul 2014, at 11:12 am, Carl Hoefs wrote: > Okay, now if I want to insert 1024 bytes of new data at the beginning of a > populated NSMutableArray, is there a better way than this: Sure; why not just do [bigMData replaceBytesInRange:NSMakeRange(0,0) withBytes:newBytesPtr length:1024]; ...

Re: [NSMutableData resetDataRangeTo:(NSRange)range];

2014-07-14 Thread Mike Abdullah
On 14 Jul 2014, at 19:12, Carl Hoefs wrote: > Okay, now if I want to insert 1024 bytes of new data at the beginning of a > populated NSMutableArray, is there a better way than this: Yes. [bigMData replaceBytesInRange:NSMakeRange(0,0) withBytes:newBytesPtr

Re: [NSMutableData resetDataRangeTo:(NSRange)range];

2014-07-14 Thread Carl Hoefs
is well optimized for shunting its contents around > internally. > > Matt > > > On 12 Jul 2014, at 20:36, Carl Hoefs wrote: > >> Basically what I would like is an NSMutableData method like this: >> >> - (void)resetDataRangeTo:(NSRange)range >> >>

Re: [NSMutableData resetDataRangeTo:(NSRange)range];

2014-07-12 Thread SevenBits
On Saturday, July 12, 2014, Carl Hoefs wrote: > On Jul 12, 2014, at 1:51 PM, Matt Gough > wrote: > > > [bigData replaceBytesInRange:NSMakeRange(0, 1024) withBytes:NULL > length:0]; > > Wow, I would never have thought to do that! Works perfectly! You could also declare a category on NSMutableDa

Re: [NSMutableData resetDataRangeTo:(NSRange)range];

2014-07-12 Thread Carl Hoefs
On Jul 12, 2014, at 1:51 PM, Matt Gough wrote: > [bigData replaceBytesInRange:NSMakeRange(0, 1024) withBytes:NULL length:0]; Wow, I would never have thought to do that! Works perfectly! Thx, -Carl ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com

Re: [NSMutableData resetDataRangeTo:(NSRange)range];

2014-07-12 Thread Matt Gough
ata method like this: > > - (void)resetDataRangeTo:(NSRange)range > > Parameters > range > The range within the contents of the receiver to be considered the new > contents. > > > But, since that doesn't exist yet, is it safe to "shift" the contents in

[NSMutableData resetDataRangeTo:(NSRange)range];

2014-07-12 Thread Carl Hoefs
Basically what I would like is an NSMutableData method like this: - (void)resetDataRangeTo:(NSRange)range Parameters range The range within the contents of the receiver to be considered the new contents. But, since that doesn't exist yet, is it safe to "shift" the contents

Re: convert CFRange to NSRange?

2010-12-14 Thread Scott Ribe
On Dec 14, 2010, at 9:58 AM, Matt Neuburg wrote: > I recognize that the conversion is not simple, but that is exactly why I am > surprised that the frameworks do not supply a utility conversion method. If I > were to write my own I would surely get it wrong. The size & layout of the members is

Re: convert CFRange to NSRange?

2010-12-14 Thread Matt Neuburg
On Sun, 12 Dec 2010 08:04:55 -0800, "John C. Randolph" said: > >On Dec 12, 2010, at 7:34 AM, Matt Neuburg wrote: > >> I feel like I'm missing something. I can't seem to typecast as >> CFRange to an NSRange. I know I can pull a CFRange apart and >

Re: convert CFRange to NSRange?

2010-12-13 Thread Gregory Weston
On Dec 13, 2010, at 04:02, John Engelhart wrote: > So, to the original poster- it's sort of like "Why is the sky blue?" > There's actually a good answer, but it's unbelievably complex and > convoluted. "So you know where to stop mowing." ___ Cocoa-dev

Re: convert CFRange to NSRange?

2010-12-13 Thread John Engelhart
On Sun, Dec 12, 2010 at 11:51 AM, Andreas Grosam wrote: > > On Dec 12, 2010, at 4:34 PM, Matt Neuburg wrote: > > > I feel like I'm missing something. I can't seem to typecast as CFRange to > an NSRange. > > Both are distinct C structs. In C, *explicitly* type

Re: convert CFRange to NSRange?

2010-12-12 Thread Andreas Grosam
On Dec 12, 2010, at 4:34 PM, Matt Neuburg wrote: > I feel like I'm missing something. I can't seem to typecast as CFRange to an > NSRange. Both are distinct C structs. In C, *explicitly* typecasting one pointer to the other would be allowed but semantically incorrect. In C++ c

Re: convert CFRange to NSRange?

2010-12-12 Thread John C. Randolph
On Dec 12, 2010, at 7:34 AM, Matt Neuburg wrote: I feel like I'm missing something. I can't seem to typecast as CFRange to an NSRange. I know I can pull a CFRange apart and reassemble it as an NSRange, but shouldn't there be a simpler way? m. CFRange is defined as a pair of

convert CFRange to NSRange?

2010-12-12 Thread Matt Neuburg
I feel like I'm missing something. I can't seem to typecast as CFRange to an NSRange. I know I can pull a CFRange apart and reassemble it as an NSRange, but shouldn't there be a simpler way? m. -- matt neuburg, phd = m...@tidbits.com, <http://www.apeth.net/matt/>

Re: Saving a PDF Selection or converting it to an NSRange and back

2009-02-12 Thread Keith Blount
Re: Saving a PDF Selection or converting it to an NSRange and back > To save a selection sapnning multiple pages you could > convert a single selection into an array of single-line > selections (-[PDFSelection selectionsByLine]). Each > selection returned by this method is going to be on a

Re: Saving a PDF Selection or converting it to an NSRange and back

2009-02-11 Thread John Calhoun
On Feb 11, 2009, at 12:44 PM, Keith Blount wrote: The subject line says it all, really, I need to save a PDFSelection between sessions in my program, but there seems no way of doing this. A similar question came up on these last year but there was no solution: To save a selection sapnning

Saving a PDF Selection or converting it to an NSRange and back

2009-02-11 Thread Keith Blount
Hi, The subject line says it all, really, I need to save a PDFSelection between sessions in my program, but there seems no way of doing this. A similar question came up on these last year but there was no solution: http://www.cocoabuilder.com/archive/message/cocoa/2008/5/16/206893 (Or at least

Re: NSRange

2008-05-14 Thread Jens Alfke
o do that, when NSXML will do the parsing for you. Learn XPath and you can extract things like your example in one line of code. I have heard of NSRange but I can't find documentation to it in xcode. Just open the documentation window and type "NSRange" into the search fiel

Re: NSRange

2008-05-14 Thread Andy Lee
On May 14, 2008, at 7:25 PM, Mr. Gecko wrote: Hello I am trying to find out how to get characters in the middle of two characters I have heard of NSRange but I can't find documentation to it in xcode. Enter "NSRange" in the search field of the Xcode documentation window

Re: NSRange

2008-05-14 Thread Mr. Gecko
I figured it out NSString *s = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://www.example.com/file.html "]]; NSRange f, l; f = [s rangeOfString:@" title=\"Title\">"]; if (f.location == NSNotFound) NSLog(@"failed"); s = [s substri

Re: NSRange

2008-05-14 Thread Randall Meadows
On May 14, 2008, at 5:25 PM, Mr. Gecko wrote: Hello I am trying to find out how to get characters in the middle of two characters I have heard of NSRange but I can't find documentation to it in xcode. > So here is what I am trying to do in this html page on line there are t

NSRange

2008-05-14 Thread Mr. Gecko
Hello I am trying to find out how to get characters in the middle of two characters I have heard of NSRange but I can't find documentation to it in xcode. So here is what I am trying to do in this html page on line there are to points which stays the same and in the middle of the poin