Skip to content

Commit c748899

Browse files
author
Atacan Durmusoglu
committed
title case, sentence commented out, my name
1 parent f9a4b50 commit c748899

File tree

15 files changed

+97
-14
lines changed

15 files changed

+97
-14
lines changed

DimeADozen.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

100755100644
File mode changed.

Shared/CaseConverter/CaseConversionViewModel.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,31 @@
88
import SwiftUI
99

1010
class CaseConversionViewModel: ObservableObject {
11+
var wordGroupSeparator: WordGroupSeperator = .newLine
1112

1213
func convert(inputText: String, from inputCase: WordGroupCase, to outputCase: WordGroupCase) -> String {
1314
convertGeneric(inputText: inputText, InputStyle: inputCase.textStyle(), OutputStyle: outputCase.textStyle())
1415
}
1516

1617
func convertGeneric(inputText: String, InputStyle: TextStyle.Type, OutputStyle: TextStyle.Type) -> String {
1718
// var outputList = [String]()
18-
let outputList = inputText.split(separator: "\n").map { word -> String in
19+
let outputList = inputText.split(separator: wordGroupSeparator.rawValue).map { word -> String in
1920
let input = InputStyle.init(String(word))
2021
let inputSplit = input.split()
22+
print("word", word)
23+
print("inputSplit", inputSplit)
2124
let output = OutputStyle.init(from: inputSplit)
2225
return output.content
2326
}
24-
return outputList.joined(separator: "\n")
27+
return outputList.joined(separator: String(wordGroupSeparator.rawValue))
28+
}
29+
30+
func seperatorDescription(_ seperatorCase: WordGroupSeperator) -> String {
31+
switch seperatorCase {
32+
case .newLine:
33+
return "New Line"
34+
default:
35+
return "Space"
36+
}
2537
}
2638
}

Shared/CaseConverter/CaseConverterView.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ struct CaseConverterView: View {
1717
@State var outputText: String = ""
1818
@State private var inputCase: WordGroupCase = .kebab
1919
@State private var outputCase: WordGroupCase = .camel
20+
@State private var seperator: WordGroupSeperator = .newLine
2021

2122
var myInputEditor: some View {
2223
VStack(alignment: .center) {
@@ -67,6 +68,12 @@ struct CaseConverterView: View {
6768
.frame(maxWidth: 250)
6869
Spacer()
6970
}
71+
Picker("Word Group Seperator", selection: $seperator) {
72+
ForEach(WordGroupSeperator.allCases) { seperator in
73+
Text(caseConversionVM.seperatorDescription(seperator))
74+
}
75+
}
76+
.frame(maxWidth: 250)
7077
Button {
7178
outputText = caseConversionVM.convert(inputText: inputText, from: inputCase, to: outputCase)
7279
} label: {

Shared/CaseConverter/TextStyle.swift

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@ enum WordCase {
1111
case allCaps
1212
}
1313

14-
enum WordGroupCase: String, CaseIterable, Identifiable {
14+
enum WordGroupCase: String, CaseIterable, Identifiable {
1515
case snake
1616
case kebab
1717
case camel
1818
case pascal
19-
var id: Self { self }
19+
case title
20+
// case sentence
2021

22+
var id: Self { self }
23+
2124
func textStyle() -> TextStyle.Type {
2225
switch self {
2326
case .snake:
@@ -28,10 +31,21 @@ enum WordGroupCase: String, CaseIterable, Identifiable {
2831
return Camel.self
2932
case .pascal:
3033
return Pascal.self
34+
case .title:
35+
return Title.self
36+
// case .sentence:
37+
// return Sentence.self
3138
}
3239
}
3340
}
3441

42+
enum WordGroupSeperator: Character, CaseIterable, Identifiable {
43+
case newLine = "\n"
44+
case space = " "
45+
46+
var id: Self { self }
47+
}
48+
3549
protocol TextStyle {
3650
var style: WordGroupCase { get }
3751
var separator: String { get }

Shared/CaseConverter/TextStyleImplement.swift

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,53 @@ struct Snake: TextStyle {
128128
return content.split(separator: Character(separator))
129129
}
130130
}
131+
132+
struct Title: TextStyle {
133+
var style = WordGroupCase.title
134+
var separator = " "
135+
var firstWordCase = WordCase.title
136+
var restWordCase = WordCase.title
137+
var content: String
138+
139+
init(_ content: String) {
140+
self.content = content
141+
}
142+
143+
init(from words: [Substring]) {
144+
content = ""
145+
let text = words
146+
.map { $0.capitalized }
147+
.joined(separator: separator)
148+
content = text
149+
}
150+
151+
func split() -> [Substring] {
152+
return content.split(separator: Character(separator))
153+
}
154+
}
155+
156+
//struct Sentence: TextStyle {
157+
// var style = WordGroupCase.sentence
158+
// var separator = "."
159+
// var firstWordCase = WordCase.title
160+
// var restWordCase = WordCase.allDown
161+
// var content: String
162+
//
163+
// func formatFirstWord(_ word: String) -> String { word.capitalized }
164+
//
165+
// init(_ content: String) {
166+
// self.content = content
167+
// }
168+
//
169+
// init(from words: [Substring]) {
170+
// content = ""
171+
// let text = words
172+
// .map { $0.capitalized }
173+
// .joined(separator: separator)
174+
// content = text
175+
// }
176+
//
177+
// func split() -> [Substring] {
178+
// return content.split(separator: Character(separator))
179+
// }
180+
//}

Shared/Main/Extensions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Extensions.swift
33
// DimeADozen
44
//
5-
// Created by atacan.durmusoglu on 11.06.22.
5+
// Created by atacan on 11.06.22.
66
//
77

88
import SwiftUI

Shared/VaporNewModel/FormVaporPropertyView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// FormVaporPropertyView.swift
33
// DimeADozen
44
//
5-
// Created by atacan.durmusoglu on 11.06.22.
5+
// Created by atacan on 11.06.22.
66
//
77

88
import SwiftUI

Shared/VaporNewModel/InputFieldViews/FieldPropertyWrapperView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// FieldPropertyWrapperView.swift
33
// DimeADozen
44
//
5-
// Created by atacan.durmusoglu on 11.06.22.
5+
// Created by atacan on 11.06.22.
66
//
77

88
import SwiftUI

Shared/VaporNewModel/InputFieldViews/LazyTextField.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// LazyTextField.swift
33
// DimeADozen
44
//
5-
// Created by atacan.durmusoglu on 12.06.22.
5+
// Created by atacan on 12.06.22.
66
//
77

88
import AppKit

Shared/VaporNewModel/InputVaporPropertyView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// InputVaporPropertyView.swift
33
// DimeADozen (iOS)
44
//
5-
// Created by atacan.durmusoglu on 11.06.22.
5+
// Created by atacan on 11.06.22.
66
//
77

88
import SwiftUI

0 commit comments

Comments
 (0)