@pixel@social.pixels.pizza
@pixel@social.pixels.pizza avatar

pixel

@pixel@social.pixels.pizza

This profile is from a federated server and may be incomplete. Browse more on the original instance.

pixel, to mentalhealth
@pixel@social.pixels.pizza avatar

Swift debugging driving me nuts.

I have a multiline file that I’ve loaded into a string using String(contentsOfFile:encoding:)

I'm trying to split the string using “someString.components(separatedBy: "==========\n“)

But it... just doesn’t. I know that particular string does exist in the file multiple times.

If I change the separator to just a linefeed it does split the file into 1600 items just fine. So for some reason it's not finding the "==========\n“ ?

I'm stumped.

pixel,
@pixel@social.pixels.pizza avatar

@GeekAndDad Nope! tried that too.

pixel,
@pixel@social.pixels.pizza avatar

@GeekAndDad it's definitely the same character - I thought the same thing so I copied it straight from the file. There's no other invisible characters (turned on invisible chars in BBEdit).

Can't escape it like that, compiler yells (as it should)

its so weird.

fun new clue: changing the separator to just “=" crashes with the error "Swift/ContiguousArrayBuffer.swift:600: Fatal error: Index out of range”

Also, this is Swift running as a command line script (i.e. with hash bang on first line)

pixel,
@pixel@social.pixels.pizza avatar

@GeekAndDad .utf8

interesting thought.

pixel,
@pixel@social.pixels.pizza avatar

@GeekAndDad ok, that's not it. tried a few others and they didn't work. opened in BBEdit and resaved as UTF8 just to make sure that's what it is, and still get the error. WEIRD.

pixel,
@pixel@social.pixels.pizza avatar

@GeekAndDad LOL ok, that was a good idea.

it's /r/n. I guess BBEdit shows the same character for /r/n and just /n EXCEPT if I do ""=\r\n" it crashes with the "Swift/ContiguousArrayBuffer.swift:600: Fatal error: Index out of range” error

pixel,
@pixel@social.pixels.pizza avatar

@krzyzanowskim yeah, I copied it straight from the file.

pixel,
@pixel@social.pixels.pizza avatar

@krzyzanowskim yup. just tried that

pixel,
@pixel@social.pixels.pizza avatar
pixel,
@pixel@social.pixels.pizza avatar

@GeekAndDad the definition for it is "func components<T>(separatedBy separator: T) -> [String] where T : StringProtocol”

pixel,
@pixel@social.pixels.pizza avatar

@GeekAndDad haha ya

pixel,
@pixel@social.pixels.pizza avatar

@GeekAndDad what the hell

pixel,
@pixel@social.pixels.pizza avatar

@krzyzanowskim uhhhh wat

pixel,
@pixel@social.pixels.pizza avatar

@GeekAndDad hmm. I'm on Xcode 15.4 interesting

pixel,
@pixel@social.pixels.pizza avatar

@GeekAndDad No luck.

pixel,
@pixel@social.pixels.pizza avatar

ok, thanks to both of you for digging into this. has to be something with my system. Even trying to just load the file and do components:separatedBy on it gives me the same issue. I'll have to look into this more later.

pixel,
@pixel@social.pixels.pizza avatar

@GeekAndDad @krzyzanowskim ok, just started on it again, and SUCCESS -

  1. There are definitely UTF16 BOM in the file.
  2. if I read the file as .utf16, it doesn't work.
  3. If I read the file as .utf8, AND strip out the UTF16 BOM, BINGO.

let cleanedClippings = clippings.replacingOccurrences(of: "\u{feff}", with: "”)

Each entry has a UTF16 marke? who knows. 332 of them in my file! I grabbed it off my kindle again just to see if I had somehow done it, but no that's how it is.

Thank you all!

pixel,
@pixel@social.pixels.pizza avatar

@gregtitus @GeekAndDad @krzyzanowskim Thanks for noticing the UTF16 BOM Greg!!

pixel,
@pixel@social.pixels.pizza avatar
textfiles, to random
@textfiles@digipres.club avatar
pixel,
@pixel@social.pixels.pizza avatar

@textfiles They're not even really trying anymore.

pixel, to apple
@pixel@social.pixels.pizza avatar

The story of how the graphing calculator application made it onto the Mac.


http://www.pacifict.com/Story/

StillIRise1963, to random
@StillIRise1963@mastodon.world avatar

Bathrooms should be divided into assholes and not assholes.

pixel,
@pixel@social.pixels.pizza avatar

@StillIRise1963 but we all have those. lol

pixel, to random
@pixel@social.pixels.pizza avatar

This theraflu needs to work faster. I need to breathe.

tubetime, to random
@tubetime@mastodon.social avatar

another silicon valley electronics flea market thread!

pixel,
@pixel@social.pixels.pizza avatar

@tubetime That might be the same electronics kit I had as a kid

fahrni, to random
@fahrni@curmudgeon.cafe avatar

I’ve been seeing a little critter run around our yard over the last few days. I think it’s a vole?

pixel,
@pixel@social.pixels.pizza avatar

@fahrni Yup looks like a vole! I love those ears.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • anitta
  • khanakhh
  • mdbf
  • InstantRegret
  • Durango
  • Youngstown
  • rosin
  • slotface
  • thenastyranch
  • osvaldo12
  • ngwrru68w68
  • kavyap
  • cisconetworking
  • DreamBathrooms
  • megavids
  • magazineikmin
  • cubers
  • vwfavf
  • modclub
  • everett
  • ethstaker
  • normalnudes
  • tacticalgear
  • tester
  • provamag3
  • GTA5RPClips
  • Leos
  • JUstTest
  • All magazines