I have no idea how a linguistic tagger determines whitespace and whether it
uses the same definition for whitespace as NSCharacterSet does. Given that it's
multi-language-aware I wouldn't be shocked to find it uses some entirely
different way of enumerating textual elements.
On 6 Apr 2015,
I imagine you’re right, that they’re NString indexes packaged up into a
frustrating return type. After sleeping on it, though, I imagined that even if
complex grapheme clusters WERE to make count( attrStr.string ) return a
different result than attrStr.length, it would probably never be due to
extension Character {
func isMemberOfSet( set:NSCharacterSet )
- Bool
{
// The for loop only executes once;
// its purpose is to convert Character to a type
// you can actually do something with
for char in String( self ).utf16 {
if set.characterIsMember(
On Apr 3, 2015, at 04:00 , Charles Jenkins cejw...@gmail.com wrote:
for char in String( self ).utf16 {
if set.characterIsMember( char ) {
return true
}
Now we’re back to the place we started. This code is wrong. It fails for any
code point that isn’t representable a
On Apr 3, 2015, at 11:04 AM, Quincey Morris
quinceymor...@rivergatesoftware.com wrote:
On Apr 3, 2015, at 04:00 , Charles Jenkins cejw...@gmail.com wrote:
for char in String( self ).utf16 {
if set.characterIsMember( char ) {
return true
}
Now we’re back to the
On Apr 3, 2015, at 11:19 , Marco S Hyman m...@snafu.org wrote:
The original code will return true only if all code points map to white space.
The “failure” I was talking about is something a bit different. It has two
problems:
1. For Unicode code points that are represented by 2 code values,
So my Character.isMemberOfSet() is a poor general-purpose method, and I need to
ditch it.
I like your code. I had to modify it a bit so it wouldn’t fall on strings
composed entirely of whitespace:
let testString = \n\n \t\t
let attrStr = NSAttributedString( string:testString )
let str =
On Apr 3, 2015, at 13:18 , Charles Jenkins cejw...@gmail.com wrote:
is there a way in the playground for use to test addresses to make sure
attrStr.string as NSString doesn’t perform a copy?
I doubt it. This is the best I could come up with in a couple of minutes:
import Cocoa
let
ok here’s my try, assuming NSLinguisticTagger knows what it’s doing. And yes
it’s a bit stupid to use a linguistic tagger to do something like that but ..
whatever
var str = Some String WIth Whitespace
var lt = NSLinguisticTagger( tagSchemes: [NSLinguisticTagSchemeTokenType],
options: 0 )
On Apr 2, 2015, at 19:28 , Charles Jenkins cejw...@gmail.com wrote:
I can indeed call attrStr.string.rangeOfCharacterFromSet(). But in typical
Swift string fashion, the return type is as unfriendly as possible:
RangeString.Index? — as if the NSString were a Swift string.
I finally read the
On Apr 2, 2015, at 19:28 , Charles Jenkins cejw...@gmail.com wrote:
So after doing two anchored searches, one at the beginning and one at the end
of the string, if I get two different ranges, I’m stuck with two values that
aren’t subtractable to determine the length of the NSRange I need in
Amen, brother.
Given my attributed string “attrStr,” I can indeed call
attrStr.string.rangeOfCharacterFromSet(). But in typical Swift string fashion,
the return type is as unfriendly as possible: RangeString.Index? — as if the
NSString were a Swift string.
So after doing two anchored
I kept my original question as brief as I could, but let me tell you what
problem I’m trying to solve, and maybe someone will have good advice I haven’t
yet considered.
I’m trying to code in pure Swift. I have an NSAttributedString which can
potentially be very large, and I want to save off
On 02 Apr 2015, at 13:54, Charles Jenkins cejw...@gmail.com
mailto:cejw...@gmail.com wrote:
What would be nice is a way to count leading and trailing characters in place
while the thing is still an NSAttributedString--without using
NSAttributedString.string to convert to a Swift string in
On Apr 2, 2015, at 6:54 AM, Charles Jenkins cejw...@gmail.com wrote:
What would be nice is a way to count leading and trailing characters in place
while the thing is still an NSAttributedString--without using
NSAttributedString.string to convert to a Swift string in the first place.
On Apr 2, 2015, at 4:54 AM, Charles Jenkins cejw...@gmail.com wrote:
What would be nice is a way to count leading and trailing characters in place
while the thing is still an NSAttributedString--without using
NSAttributedString.string to convert to a Swift string in the first place. If
The documentation certainly says that, Ken, but stick this code in a playground
and see that you can’t examine the characters via index no matter whether you
assume it to be String or NSString:
let whitespaceSet = NSCharacterSet.whitespaceAndNewlineCharacterSet()
let attrStr =
Oops. My documentation viewer was set up wrong. characterAtIndex() is indeed
supposed to be available in Swift. Don’t know what I’ve done wrong that I can’t
use it in a playground.
--
Charles
On April 2, 2015 at 10:18:00, Charles Jenkins (cejw...@gmail.com) wrote:
The documentation
On Apr 2, 2015, at 04:54 , Charles Jenkins cejw...@gmail.com wrote:
Swift has a built-in func stringByTrimmingCharactersInSet(set:
NSCharacterSet) - String
There is something wacky going on here — or not. (I know you don’t want to use
this particular method, but I’m just using it as an
On Apr 1, 2015, at 21:17 , Charles Jenkins cejw...@gmail.com wrote:
for ch in String(char).utf16 {
if !set.characterIsMember(ch) { found = false }
}
Except that this code can’t possibly be right, in general.
1. A ‘unichar’ is a UTF-16 code value, but it’s not a Unicode code point.
On Apr 1, 2015, at 8:14 PM, Charles Jenkins cejw...@gmail.com wrote:
Given this code:
let someCharacter = str[str.endIndex.predecessor()]
How can I determine if someCharacter is whitespace?
import Foundation
func isChar(char: Character, inSet set: NSCharacterSet) - Bool {
// this
Thank you very much. :-) I had been trying to figure out how to use
NSCharacterSet, but I didn’t know the bit about converting to UTF-16 string
first.
—
Charles
On April 1, 2015 at 9:52:47 PM, Charles Srstka (cocoa...@charlessoft.com) wrote:
On Apr 1, 2015, at 8:14 PM, Charles Jenkins
22 matches
Mail list logo