<commit_before>﻿import Foundation
import AppKit

@objc public class FooDocument : NSDocument {

	//
	// NSDocument implementation
	//

	override init(type: String?, error: UnsafePointer<NSError>) { // workaround for invalid NSError pointer being passed in, sometimes
		data = FooDocumentData()
	}

	override func read(from url: URL, ofType typeName: NSString) throws {
		try! loadDocument(from: url)
	}

	override func write(to url: URL, ofType typeName: NSString, `for` saveOperation: NSSaveOperationType, originalContentsURL absoluteOriginalContentsURL: URL?) throws {
		try! saveDocument(to: url)
	}

	override func makeWindowControllers() {
		addWindowController(FooDocumentWindowController(document: self))
	}

	override class var autosavesInPlace: Bool {
		return true // enables the title bar menu, among other things
	}

	//
	// Custom members
	//

	func loadDocument(from url: URL) throws {
		data = FooDocumentData(from: url)
		if data == nil {
			throw RemObjects.Elements.System.Exception("Count not load document.")
		}
	}

	func saveDocument(to url: URL) throws {
		if let data = data {
			data.save(to: url)
		}
		throw RemObjects.Elements.System.Exception("Count not save document.")
	}

	public var data: FooDocumentData?

}

//
// data stored in the document:
//

public class FooDocumentData {

	var text: String;

	init() {
		text = "New Foo!"
	}

	init?(from url: URL) {
		if File.Exists(url.path) {
			text = File.ReadText(url.path)
		} else {
			return nil
		}
	}

	func save(to url: URL) {
		File.WriteText(url.path, text)
	}

}<commit_msg>82315: Samples: Island: confused about String vs File<commit_after>﻿import Foundation
import AppKit

@objc public class FooDocument : NSDocument {

	//
	// NSDocument implementation
	//

	override init(type: String?, error: UnsafePointer<NSError>) { // workaround for invalid NSError pointer being passed in, sometimes
		data = FooDocumentData()
	}

	override func read(from url: URL, ofType typeName: NSString) throws {
		try! loadDocument(from: url)
	}

	override func write(to url: URL, ofType typeName: NSString, `for` saveOperation: NSSaveOperationType, originalContentsURL absoluteOriginalContentsURL: URL?) throws {
		try! saveDocument(to: url)
	}

	override func makeWindowControllers() {
		addWindowController(FooDocumentWindowController(document: self))
	}

	override class var autosavesInPlace: Bool {
		return true // enables the title bar menu, among other things
	}

	//
	// Custom members
	//

	func loadDocument(from url: URL) throws {
		data = FooDocumentData(from: url)
		if data == nil {
			throw RemObjects.Elements.System.Exception("Count not load document.")
		}
	}

	func saveDocument(to url: URL) throws {
		if let data = data {
			data.save(to: url)
		}
		throw RemObjects.Elements.System.Exception("Count not save document.")
	}

	public var data: FooDocumentData?

}

//
// data stored in the document:
//

public class FooDocumentData {

	var text: String;

	init() {
		text = "New Foo!"
	}

	init?(from url: URL) {
		if (url.path as! RemObjects.Elements.RTL.File)?.Exists() {
			text = File.ReadText(url.path)
		} else {
			return nil
		}
	}

	func save(to url: URL) {
		File.WriteText(url.path, text)
	}

}
{'fraction_non_alphanumeric': 0.11, 'fraction_numerical': 0.0015625, 'mean_word_length': 3.8573596358118363, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '126408', 'n_tokens_mistral': 1111, 'n_tokens_neox': 1008, 'n_words': 301}