الفرق بين المراجعتين ل"Kotlin/kotlin.text/offsetByCodePoints"

من موسوعة حسوب
اذهب إلى التنقل اذهب إلى البحث
ط (استبدال النص - 'Kotlin Functions' ب'Kotlin Function')
ط
 
(مراجعة متوسطة واحدة بواسطة نفس المستخدم غير معروضة)
سطر 1: سطر 1:
<noinclude>{{DISPLAYTITLE: الدالة <code>text.offsetByCodePoints()‎</code> في لغة Kotlin}}</noinclude>
+
<noinclude>{{DISPLAYTITLE: الدالة <code>String.offsetByCodePoints()‎</code> في Kotlin}}</noinclude>
تعيد الدالة <code>offsetByCodePoints()‎</code>  الفهرس في [[Kotlin/String|السلسلة النصية]] التي استٌدعيت عبرها والذي يكون إزاحة (offset) من الوسيط <code>index</code> عبر  كود اليونيكود (Unicode code point)المُمرّر <code>codePointOffset</code>.  
+
تعيد الدالة <code>offsetByCodePoints()‎</code>  فهرس المحرف الموجود في [[Kotlin/String|السلسلة النصية]] التي استٌدعيت معها والذي ينزاح بمقدار محدد بدءًا من عنصر ذي فهرس محدد.  
 
==البنية العامة==
 
==البنية العامة==
 
<syntaxhighlight lang="kotlin">
 
<syntaxhighlight lang="kotlin">
سطر 7: سطر 7:
 
     codePointOffset: Int
 
     codePointOffset: Int
 
): Int  
 
): Int  
</syntaxhighlight>يُلاحَظ وجود الكلمة المفتاحية <code>inline</code> للدلالة على أن هذه الدالة مباشرة، وللمزيد من التفاصيل راجع <nowiki/>[[Kotlin/inline functions|توثيق الدوال المباشرة (inline functions)]].
+
</syntaxhighlight>منصة التشغيل المطلوبة: '''JVM'''.
 +
 
 +
وجود الكلمة المفتاحية <code>inline</code> يدل على أن هذه الدالة مباشرة (للمزيد من التفاصيل، راجع صفحة <nowiki/>[[Kotlin/inline functions|الدوال المباشرة (inline functions)]]).
 +
 
 +
== المعاملات ==
 +
 
 +
=== <code>index</code> ===
 +
عدد صحيح يمثل فهرس العنصر الذي ستبدأ عنده عملية الإزاحة.
 +
 
 +
=== <code>codePointOffset</code> ===
 +
عدد صحيح يمثل مقدار الإزاحة.
  
 
==القيم المعادة==
 
==القيم المعادة==
 
عدد من النوع <code>Int</code>.  
 
عدد من النوع <code>Int</code>.  
 
==أمثلة==
 
==أمثلة==
===استخدام الدالة <code>()offsetByCodePoints</code> مع سلسلة نصية===
+
مثالٌ على استعمال الدالة <code>()offsetByCodePoints</code><nowiki/>:<syntaxhighlight lang="kotlin">
تعرِّف الشيفرة الآتية سلسلة نصية باسم <code>str</code>، ثمَّ تستدعي الدالة <code>()offsetByCodePoints</code> عبرها مع تمرير عددين كوسيطين، <nowiki/>ثمَّ تطبع الناتج:<syntaxhighlight lang="kotlin">
+
fun main(args: Array<String>) {
 +
    val str = "Hsoub"
 +
 
 +
    print(str.offsetByCodePoints(0, 3)) // 3
 +
    print(str.offsetByCodePoints(2, 3)) // 5
 +
}
 +
</syntaxhighlight>مثالٌ آخر على استعمال الدالة <code>()offsetByCodePoints</code>:<syntaxhighlight lang="kotlin">
 
fun main(args: Array<String>) {
 
fun main(args: Array<String>) {
val str = "Hsoub"  
+
    val str = "Hsoub"
  
print(str.offsetByCodePoints(0, 4)) // 4
+
    print(str.offsetByCodePoints(0, 6)) // 3
 
}
 
}
 +
</syntaxhighlight>يرمي هذا المثال عند تنفيذه الاستثناء <code>IndexOutOfBoundsException</code>:<syntaxhighlight lang="text">
 +
Exception in thread "main" java.lang.IndexOutOfBoundsException
 +
at java.base/java.lang.Character.offsetByCodePoints(Character.java:8225)
 +
at java.base/java.lang.String.offsetByCodePoints(String.java:819)
 +
at TestKt.main(test.kt:4)
 
</syntaxhighlight>
 
</syntaxhighlight>
===انظر أيضًا===
 
* <code>[[Kotlin/kotlin.text/codePointBefore|codePointBefore()]]‎</code>: تعيد كود اليونيكود (Unicode code point) للحرف الموجود قبل الفهرس المُحدّد. 
 
  
* <code>[[Kotlin/kotlin.text/associateByTo|associateByTo()]]‎</code>: تعيد قاموسا متغيرا (mutable map) يحتوي أزواجًا من "مفتاح/قيمة"، إذ القيمة هي عناصر سلسلة الحروف التي استُدعيت عبرها، والمفتاح هو الناتج المعاد من تمرير تلك العناصر إلى الدالة <code>keySelector</code>. 
+
==انظر أيضًا==
* <code>[[Kotlin/kotlin.text/asSequence|asSequence()]]‎</code>: تنشئ كائنًا من الصنف <code>Sequence</code> والذي يُغلّف سلسلة الحروف التي استُدعيت عبرها، لأجل استعمالها في الحلقات التكرارية.
+
* الدالة <code>[[Kotlin/kotlin.text/codePointBefore|codePointBefore()]]‎</code>: تعيد المحرف (Unicode code point) الموجود قبل الفهرس المُحدّد.
 +
* الدالة <code>[[Kotlin/kotlin.text/codePointAt|codePointAt()]]‎</code>: تعيد المحرف (Unicode code point) عند الفهرس المُحدّد. 
  
 
==مصادر==
 
==مصادر==
*[http://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/offset-by-code-points.html الدالة text.offsetByCodePoints()‎ في التوثيق الرسميّ للمكتبة القياسيّة في لغة Kotlin.]
+
*[http://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/offset-by-code-points.html صفحة الدالة String.offsetByCodePoints()‎ في التوثيق الرسميّ للمكتبة القياسيّة في لغة Kotlin.]
 
[[تصنيف:Kotlin]]
 
[[تصنيف:Kotlin]]
 
[[تصنيف:Kotlin Function]]
 
[[تصنيف:Kotlin Function]]
 +
[[تصنيف:Kotlin Text]]
 +
[[تصنيف:Kotlin CharSequence]]

المراجعة الحالية بتاريخ 16:01، 4 سبتمبر 2018

تعيد الدالة offsetByCodePoints()‎ فهرس المحرف الموجود في السلسلة النصية التي استٌدعيت معها والذي ينزاح بمقدار محدد بدءًا من عنصر ذي فهرس محدد.

البنية العامة

inline fun String.offsetByCodePoints(
    index: Int, 
    codePointOffset: Int
): Int

منصة التشغيل المطلوبة: JVM.

وجود الكلمة المفتاحية inline يدل على أن هذه الدالة مباشرة (للمزيد من التفاصيل، راجع صفحة الدوال المباشرة (inline functions)).

المعاملات

index

عدد صحيح يمثل فهرس العنصر الذي ستبدأ عنده عملية الإزاحة.

codePointOffset

عدد صحيح يمثل مقدار الإزاحة.

القيم المعادة

عدد من النوع Int.

أمثلة

مثالٌ على استعمال الدالة ()offsetByCodePoints:

fun main(args: Array<String>) {
    val str = "Hsoub"

    print(str.offsetByCodePoints(0, 3)) // 3
    print(str.offsetByCodePoints(2, 3)) // 5
}

مثالٌ آخر على استعمال الدالة ()offsetByCodePoints:

fun main(args: Array<String>) {
    val str = "Hsoub"

    print(str.offsetByCodePoints(0, 6)) // 3
}

يرمي هذا المثال عند تنفيذه الاستثناء IndexOutOfBoundsException:

Exception in thread "main" java.lang.IndexOutOfBoundsException
	at java.base/java.lang.Character.offsetByCodePoints(Character.java:8225)
	at java.base/java.lang.String.offsetByCodePoints(String.java:819)
	at TestKt.main(test.kt:4)

انظر أيضًا

  • الدالة codePointBefore(): تعيد المحرف (Unicode code point) الموجود قبل الفهرس المُحدّد.
  • الدالة codePointAt(): تعيد المحرف (Unicode code point) عند الفهرس المُحدّد. 

مصادر