Commit Graph
2 Commits
Author SHA1 Message Date
David Richardson 021e9935aa Foundation: Add CPProgress and cancellable item provider loading
Partial implementation, gaps and impossibilities noted internally as TODO comments.

* CPProgress.j: Introduce CPProgress, modelled on NSProgress.
  - Count units of work, with fraction completed, finished and indeterminate states.
  - Compose progress trees through explicit children and the current progress object.
  - Cancel, pause and resume, with handlers, propagating to children.
  - Announce unit-count changes through key-value observing across the tree.

* CPError.j: Add CPUserCancelledError.

* CPItemProvider.j:
  - Return a CPProgress from each load, counting bytes read for files and aborting the read on cancellation.
  - Pass file contents to CPData as a binary string rather than a byte array.
  - Implement -canLoadObjectOfClass: and -loadObjectOfClass:completionHandler:.
  - Add the CPString (CPItemProvider) reading category.

* CPString+Encoding.j: Decode data held as a binary string through a Uint8Array, without building a byte array.

* Foundation.j: Import CPProgress.j.

* CPProgressTest.j: Add unit tests covering counts, children, the current progress object, cancellation, pausing, observation and user information.

* CPItemProviderTest.j: Add unit tests covering read progress, cancellation, completion and string loading.
2026-11-02 15:29:21 -06:00
David Richardson 161f6be214 Foundation: Add encoding conversion API to CPString
* CPString+Encoding.j: Introduce Cocoa encoding constants and the CPString (CPStringEncoding) category.
  - Implement decoding and encoding via -initWithData:encoding:, -initWithBytes:length:encoding:, -dataUsingEncoding:, and -dataUsingEncoding:allowLossyConversion:.
  - Implement -canBeConvertedToEncoding:, -lengthOfBytesUsingEncoding:, -maximumLengthOfBytesUsingEncoding:, -fastestEncoding, and -smallestEncoding.
  - Add +availableStringEncodings, terminated by 0 matching Cocoa conventions.
  - Add +localizedNameOfStringEncoding:, +defaultCStringEncoding, and encoding detection via +stringEncodingForData:encodingOptions:convertedString:usedLossyConversion:.
  - Document remaining NSString compatibility gaps via TODO comments.
* Foundation.j: Import CPString+Encoding.j.
* CPStringEncodingTest.j: Add unit tests covering encodings, lossy conversion, byte lengths, encoding detection, and available encodings.
2026-11-02 14:48:32 -06:00