Skip to content

Commit 22b29e3

Browse files
authored
Merge pull request #513 from MohamedRejeb/1.x
Add OrderedListStyleType.Arabic
2 parents bccf1e9 + 2c6c214 commit 22b29e3

File tree

5 files changed

+84
-2
lines changed

5 files changed

+84
-2
lines changed

richeditor-compose/api/android/richeditor-compose.api

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,20 @@ public abstract interface class com/mohamedrejeb/richeditor/paragraph/type/Order
232232
public abstract fun getSuffix (I)Ljava/lang/String;
233233
}
234234

235+
public final class com/mohamedrejeb/richeditor/paragraph/type/OrderedListStyleType$Arabic : com/mohamedrejeb/richeditor/paragraph/type/OrderedListStyleType {
236+
public static final field $stable I
237+
public static final field INSTANCE Lcom/mohamedrejeb/richeditor/paragraph/type/OrderedListStyleType$Arabic;
238+
public fun format (II)Ljava/lang/String;
239+
public fun getSuffix (I)Ljava/lang/String;
240+
}
241+
242+
public final class com/mohamedrejeb/richeditor/paragraph/type/OrderedListStyleType$ArabicIndic : com/mohamedrejeb/richeditor/paragraph/type/OrderedListStyleType {
243+
public static final field $stable I
244+
public static final field INSTANCE Lcom/mohamedrejeb/richeditor/paragraph/type/OrderedListStyleType$ArabicIndic;
245+
public fun format (II)Ljava/lang/String;
246+
public fun getSuffix (I)Ljava/lang/String;
247+
}
248+
235249
public final class com/mohamedrejeb/richeditor/paragraph/type/OrderedListStyleType$Decimal : com/mohamedrejeb/richeditor/paragraph/type/OrderedListStyleType {
236250
public static final field $stable I
237251
public static final field INSTANCE Lcom/mohamedrejeb/richeditor/paragraph/type/OrderedListStyleType$Decimal;

richeditor-compose/api/desktop/richeditor-compose.api

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,20 @@ public abstract interface class com/mohamedrejeb/richeditor/paragraph/type/Order
232232
public abstract fun getSuffix (I)Ljava/lang/String;
233233
}
234234

235+
public final class com/mohamedrejeb/richeditor/paragraph/type/OrderedListStyleType$Arabic : com/mohamedrejeb/richeditor/paragraph/type/OrderedListStyleType {
236+
public static final field $stable I
237+
public static final field INSTANCE Lcom/mohamedrejeb/richeditor/paragraph/type/OrderedListStyleType$Arabic;
238+
public fun format (II)Ljava/lang/String;
239+
public fun getSuffix (I)Ljava/lang/String;
240+
}
241+
242+
public final class com/mohamedrejeb/richeditor/paragraph/type/OrderedListStyleType$ArabicIndic : com/mohamedrejeb/richeditor/paragraph/type/OrderedListStyleType {
243+
public static final field $stable I
244+
public static final field INSTANCE Lcom/mohamedrejeb/richeditor/paragraph/type/OrderedListStyleType$ArabicIndic;
245+
public fun format (II)Ljava/lang/String;
246+
public fun getSuffix (I)Ljava/lang/String;
247+
}
248+
235249
public final class com/mohamedrejeb/richeditor/paragraph/type/OrderedListStyleType$Decimal : com/mohamedrejeb/richeditor/paragraph/type/OrderedListStyleType {
236250
public static final field $stable I
237251
public static final field INSTANCE Lcom/mohamedrejeb/richeditor/paragraph/type/OrderedListStyleType$Decimal;

richeditor-compose/api/richeditor-compose.klib.api

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ abstract interface com.mohamedrejeb.richeditor.paragraph.type/OrderedListStyleTy
107107
final fun getSuffix(kotlin/Int): kotlin/String // com.mohamedrejeb.richeditor.paragraph.type/OrderedListStyleType.Multiple.getSuffix|getSuffix(kotlin.Int){}[0]
108108
}
109109

110+
final object Arabic : com.mohamedrejeb.richeditor.paragraph.type/OrderedListStyleType { // com.mohamedrejeb.richeditor.paragraph.type/OrderedListStyleType.Arabic|null[0]
111+
final fun format(kotlin/Int, kotlin/Int): kotlin/String // com.mohamedrejeb.richeditor.paragraph.type/OrderedListStyleType.Arabic.format|format(kotlin.Int;kotlin.Int){}[0]
112+
}
113+
114+
final object ArabicIndic : com.mohamedrejeb.richeditor.paragraph.type/OrderedListStyleType { // com.mohamedrejeb.richeditor.paragraph.type/OrderedListStyleType.ArabicIndic|null[0]
115+
final fun format(kotlin/Int, kotlin/Int): kotlin/String // com.mohamedrejeb.richeditor.paragraph.type/OrderedListStyleType.ArabicIndic.format|format(kotlin.Int;kotlin.Int){}[0]
116+
}
117+
110118
final object Decimal : com.mohamedrejeb.richeditor.paragraph.type/OrderedListStyleType { // com.mohamedrejeb.richeditor.paragraph.type/OrderedListStyleType.Decimal|null[0]
111119
final fun format(kotlin/Int, kotlin/Int): kotlin/String // com.mohamedrejeb.richeditor.paragraph.type/OrderedListStyleType.Decimal.format|format(kotlin.Int;kotlin.Int){}[0]
112120
}
@@ -366,6 +374,8 @@ final val com.mohamedrejeb.richeditor.model/com_mohamedrejeb_richeditor_model_Ri
366374
final val com.mohamedrejeb.richeditor.model/com_mohamedrejeb_richeditor_model_TextPaddingValues$stableprop // com.mohamedrejeb.richeditor.model/com_mohamedrejeb_richeditor_model_TextPaddingValues$stableprop|#static{}com_mohamedrejeb_richeditor_model_TextPaddingValues$stableprop[0]
367375
final val com.mohamedrejeb.richeditor.paragraph.type/com_mohamedrejeb_richeditor_paragraph_type_DefaultParagraph$stableprop // com.mohamedrejeb.richeditor.paragraph.type/com_mohamedrejeb_richeditor_paragraph_type_DefaultParagraph$stableprop|#static{}com_mohamedrejeb_richeditor_paragraph_type_DefaultParagraph$stableprop[0]
368376
final val com.mohamedrejeb.richeditor.paragraph.type/com_mohamedrejeb_richeditor_paragraph_type_OrderedList$stableprop // com.mohamedrejeb.richeditor.paragraph.type/com_mohamedrejeb_richeditor_paragraph_type_OrderedList$stableprop|#static{}com_mohamedrejeb_richeditor_paragraph_type_OrderedList$stableprop[0]
377+
final val com.mohamedrejeb.richeditor.paragraph.type/com_mohamedrejeb_richeditor_paragraph_type_OrderedListStyleType_Arabic$stableprop // com.mohamedrejeb.richeditor.paragraph.type/com_mohamedrejeb_richeditor_paragraph_type_OrderedListStyleType_Arabic$stableprop|#static{}com_mohamedrejeb_richeditor_paragraph_type_OrderedListStyleType_Arabic$stableprop[0]
378+
final val com.mohamedrejeb.richeditor.paragraph.type/com_mohamedrejeb_richeditor_paragraph_type_OrderedListStyleType_ArabicIndic$stableprop // com.mohamedrejeb.richeditor.paragraph.type/com_mohamedrejeb_richeditor_paragraph_type_OrderedListStyleType_ArabicIndic$stableprop|#static{}com_mohamedrejeb_richeditor_paragraph_type_OrderedListStyleType_ArabicIndic$stableprop[0]
369379
final val com.mohamedrejeb.richeditor.paragraph.type/com_mohamedrejeb_richeditor_paragraph_type_OrderedListStyleType_Decimal$stableprop // com.mohamedrejeb.richeditor.paragraph.type/com_mohamedrejeb_richeditor_paragraph_type_OrderedListStyleType_Decimal$stableprop|#static{}com_mohamedrejeb_richeditor_paragraph_type_OrderedListStyleType_Decimal$stableprop[0]
370380
final val com.mohamedrejeb.richeditor.paragraph.type/com_mohamedrejeb_richeditor_paragraph_type_OrderedListStyleType_LowerAlpha$stableprop // com.mohamedrejeb.richeditor.paragraph.type/com_mohamedrejeb_richeditor_paragraph_type_OrderedListStyleType_LowerAlpha$stableprop|#static{}com_mohamedrejeb_richeditor_paragraph_type_OrderedListStyleType_LowerAlpha$stableprop[0]
371381
final val com.mohamedrejeb.richeditor.paragraph.type/com_mohamedrejeb_richeditor_paragraph_type_OrderedListStyleType_LowerRoman$stableprop // com.mohamedrejeb.richeditor.paragraph.type/com_mohamedrejeb_richeditor_paragraph_type_OrderedListStyleType_LowerRoman$stableprop|#static{}com_mohamedrejeb_richeditor_paragraph_type_OrderedListStyleType_LowerRoman$stableprop[0]
@@ -402,6 +412,8 @@ final fun com.mohamedrejeb.richeditor.model/com_mohamedrejeb_richeditor_model_Te
402412
final fun com.mohamedrejeb.richeditor.model/rememberRichTextState(androidx.compose.runtime/Composer?, kotlin/Int): com.mohamedrejeb.richeditor.model/RichTextState // com.mohamedrejeb.richeditor.model/rememberRichTextState|rememberRichTextState(androidx.compose.runtime.Composer?;kotlin.Int){}[0]
403413
final fun com.mohamedrejeb.richeditor.paragraph.type/com_mohamedrejeb_richeditor_paragraph_type_DefaultParagraph$stableprop_getter(): kotlin/Int // com.mohamedrejeb.richeditor.paragraph.type/com_mohamedrejeb_richeditor_paragraph_type_DefaultParagraph$stableprop_getter|com_mohamedrejeb_richeditor_paragraph_type_DefaultParagraph$stableprop_getter(){}[0]
404414
final fun com.mohamedrejeb.richeditor.paragraph.type/com_mohamedrejeb_richeditor_paragraph_type_OrderedList$stableprop_getter(): kotlin/Int // com.mohamedrejeb.richeditor.paragraph.type/com_mohamedrejeb_richeditor_paragraph_type_OrderedList$stableprop_getter|com_mohamedrejeb_richeditor_paragraph_type_OrderedList$stableprop_getter(){}[0]
415+
final fun com.mohamedrejeb.richeditor.paragraph.type/com_mohamedrejeb_richeditor_paragraph_type_OrderedListStyleType_Arabic$stableprop_getter(): kotlin/Int // com.mohamedrejeb.richeditor.paragraph.type/com_mohamedrejeb_richeditor_paragraph_type_OrderedListStyleType_Arabic$stableprop_getter|com_mohamedrejeb_richeditor_paragraph_type_OrderedListStyleType_Arabic$stableprop_getter(){}[0]
416+
final fun com.mohamedrejeb.richeditor.paragraph.type/com_mohamedrejeb_richeditor_paragraph_type_OrderedListStyleType_ArabicIndic$stableprop_getter(): kotlin/Int // com.mohamedrejeb.richeditor.paragraph.type/com_mohamedrejeb_richeditor_paragraph_type_OrderedListStyleType_ArabicIndic$stableprop_getter|com_mohamedrejeb_richeditor_paragraph_type_OrderedListStyleType_ArabicIndic$stableprop_getter(){}[0]
405417
final fun com.mohamedrejeb.richeditor.paragraph.type/com_mohamedrejeb_richeditor_paragraph_type_OrderedListStyleType_Decimal$stableprop_getter(): kotlin/Int // com.mohamedrejeb.richeditor.paragraph.type/com_mohamedrejeb_richeditor_paragraph_type_OrderedListStyleType_Decimal$stableprop_getter|com_mohamedrejeb_richeditor_paragraph_type_OrderedListStyleType_Decimal$stableprop_getter(){}[0]
406418
final fun com.mohamedrejeb.richeditor.paragraph.type/com_mohamedrejeb_richeditor_paragraph_type_OrderedListStyleType_LowerAlpha$stableprop_getter(): kotlin/Int // com.mohamedrejeb.richeditor.paragraph.type/com_mohamedrejeb_richeditor_paragraph_type_OrderedListStyleType_LowerAlpha$stableprop_getter|com_mohamedrejeb_richeditor_paragraph_type_OrderedListStyleType_LowerAlpha$stableprop_getter(){}[0]
407419
final fun com.mohamedrejeb.richeditor.paragraph.type/com_mohamedrejeb_richeditor_paragraph_type_OrderedListStyleType_LowerRoman$stableprop_getter(): kotlin/Int // com.mohamedrejeb.richeditor.paragraph.type/com_mohamedrejeb_richeditor_paragraph_type_OrderedListStyleType_LowerRoman$stableprop_getter|com_mohamedrejeb_richeditor_paragraph_type_OrderedListStyleType_LowerRoman$stableprop_getter(){}[0]

richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/paragraph/type/OrderedListStyleType.kt

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,22 @@ public interface OrderedListStyleType {
7777
}
7878

7979
/**
80-
* Lowercase letters style (a, b, c, ...)
80+
* Arabic letters style (ا, ب, ج, ...)
81+
*/
82+
public object Arabic: OrderedListStyleType {
83+
internal val arabicLetters = charArrayOf(
84+
'أ', 'ب', 'ج', 'د', 'ه', 'و', 'ز', 'ح', 'ط', 'ي', 'ك', 'ل', 'م',
85+
'ن', 'س', 'ع', 'ف', 'ص', 'ق', 'ر', 'ش', 'ت', 'ث', 'خ', 'ذ', 'ض', 'ظ', 'غ'
86+
)
87+
88+
override fun format(number: Int, listLevel: Int): String =
89+
formatToArabic(
90+
number = number,
91+
)
92+
}
93+
94+
/**
95+
* Lowercase latin letters style (a, b, c, ...)
8196
*/
8297
public object LowerAlpha : OrderedListStyleType {
8398
override fun format(number: Int, listLevel: Int): String =
@@ -88,7 +103,7 @@ public interface OrderedListStyleType {
88103
}
89104

90105
/**
91-
* Uppercase letters style (A, B, C, ...)
106+
* Uppercase latin letters style (A, B, C, ...)
92107
*/
93108
public object UpperAlpha : OrderedListStyleType {
94109
override fun format(number: Int, listLevel: Int): String =
@@ -176,6 +191,22 @@ public interface OrderedListStyleType {
176191

177192
private companion object {
178193

194+
private fun formatToArabic(
195+
number: Int,
196+
): String {
197+
if (number <= 0)
198+
return Arabic.arabicLetters.first().toString()
199+
200+
val result = StringBuilder()
201+
var n = number
202+
while (n > 0) {
203+
val remainder = (n - 1) % 28
204+
result.insert(0, Arabic.arabicLetters[remainder])
205+
n = (n - 1) / 28
206+
}
207+
return result.toString()
208+
}
209+
179210
private fun formatToAlpha(
180211
number: Int,
181212
base: Char,

richeditor-compose/src/commonTest/kotlin/com/mohamedrejeb/richeditor/paragraph/type/OrderedListStyleTypeTest.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ class OrderedListStyleTypeTest {
2424
assertEquals("", styleType.format(-1, 1))
2525
}
2626

27+
@Test
28+
fun testArabicFormat() {
29+
val styleType = OrderedListStyleType.Arabic
30+
assertEquals("أ", styleType.format(1, 1))
31+
assertEquals("ب", styleType.format(2, 1))
32+
assertEquals("غ", styleType.format(28, 1))
33+
assertEquals("أأ", styleType.format(29, 1))
34+
assertEquals("أب", styleType.format(30, 1))
35+
assertEquals("أ", styleType.format(0, 1))
36+
}
37+
2738
@Test
2839
fun testLowerAlphaFormat() {
2940
val styleType = OrderedListStyleType.LowerAlpha

0 commit comments

Comments
 (0)