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

من موسوعة حسوب
اذهب إلى التنقل اذهب إلى البحث
ط (استبدال النص - '==القيمة المُعادة==' ب'==القيمة المعادة==')
(مراجعة وتدقيق.)
 
سطر 1: سطر 1:
<noinclude>{{DISPLAYTITLE: الخاصية <code>MatchResult.destructured‎</code> في لغة Kotlin}}</noinclude>
+
<noinclude>{{DISPLAYTITLE: الخاصية <code>MatchResult.destructured‎</code> في Kotlin}}</noinclude>
الخاصية <code>destructured‎</code> تعيد نسخة من الصنف <code>[[Kotlin/kotlin.text/MatchResult/Destructured/index|MatchResult.Destructured]]،</code> والتي توفّر مركبات لتفكيك قيم المجموعة المُطابقة. المركبة الأولى تقابل قيمة المجموعة المُطابقَة الأولى، والمركبة الثانية تقابل الثانية، وهكذا دواليك.
+
تمثل الخاصية <code>MatchResult.destructured‎</code> نسخةً من الصنف <code>[[Kotlin/kotlin.text/MatchResult/Destructured|Destructured]]</code> توفّر مكونات عملية الإسناد بالتفكيك (destructuring assignment) التي تطبق على قيم المجموعة المُطابقة.
 +
 
 +
تطابق الدالة <code>[[Kotlin/kotlin.text/MatchResult/Destructured/component1|component1]]</code> قيمة المجموعة الأولى، وتطابق الدالة <code>[[Kotlin/kotlin.text/MatchResult/Destructured/component2|component2]]</code> قيمة المجموعة الثانية، وهلم جرًا.
 
==البنية العامة==
 
==البنية العامة==
 
<syntaxhighlight lang="kotlin">
 
<syntaxhighlight lang="kotlin">
سطر 7: سطر 9:
 
</syntaxhighlight>
 
</syntaxhighlight>
 
==القيمة المعادة==
 
==القيمة المعادة==
نسخة من الصنف <code>[[Kotlin/kotlin.text/MatchResult/Destructured/index|MatchResult.Destructured]]</code>.
+
تعاد نسخةٌ من الصنف <code>[[Kotlin/kotlin.text/MatchResult/Destructured|Destructured]]</code>.
 
==أمثلة==
 
==أمثلة==
===استخدام الخاصية <code>destructured‎</code>===
+
ينشِئ التابع <code>Regex()‎</code> في الشيفرة التالية تعبيرًا نمطيًا باسم <code>regex</code> لتفكيك مسارات الملفات إلى ثلاث مُركّبات: المجلد (directory) واسم الملف (fileName) والامتداد (extension)، ثم نعرّف سلسلة نصية باسم <code>fullPath</code> تحتوي مسار أحد الملفات، ثم نستخرج من <code>fullPath</code>  مجموعات النتائج عبر استدعاء الدالة <code>matchEntire()‎</code> مع <code>regex</code> وتمرير  <code>fullPath</code> إليها كوسيط. نستخدم بعدئذٍ الخاصية <code>MatchResult.destructured</code> لاستخراج مجموعات النتائج:<syntaxhighlight lang="kotlin">
ينشِئ التابع <code>Regex()‎</code> في الشيفرة الآتية تعبيرًا نمطيًا باسم <code>regex</code> لتفكيك مسارات الملفات إلى ثلاث مُركّبات: المجلد (<code>directory</code>) واسم الملف (<code>fileName</code>) والامتداد (<code>extension</code>)، ثم نعرّف سلسلة نصية باسم <code>fullPath</code> تحتوي مسار أحد الملفات، ثم نستخرج من <code>fullPath</code>  مجموعات النتائج عبر استدعاء الدالة<code>matchEntire()‎</code>  عبر  <code>regex</code> وتمرير  <code>fullPath</code> إليها كوسيط، ثم نستخدم الخاصية<code>destructured‎</code> لاستخراج مجموعات النتائج، ثم نطبع الناتج:<syntaxhighlight lang="kotlin">
 
 
package com.kotlination.filename
 
package com.kotlination.filename
  
 
fun main(args: Array<String>) {
 
fun main(args: Array<String>) {
  
val fullPath = "Kotlination/Kotlin/Practice/getFileNameExample.kt"
+
    val fullPath = "Kotlination/Kotlin/Practice/getFileNameExample.kt"
  
val regex = """(.+)/(.+)\.(.+)""".toRegex()
+
    val regex = """(.+)/(.+)\.(.+)""".toRegex()
val matchResult = regex.matchEntire(fullPath)
+
    val matchResult = regex.matchEntire(fullPath)
  
if (matchResult != null) {
+
    if (matchResult != null) {
  val (directory, fileName, extension) = matchResult.destructured
+
        val (directory, fileName, extension) = matchResult.destructured
  println("dir: $directory | fileName: $fileName | extension: $extension")
+
        println("dir: $directory | fileName: $fileName | extension: $extension")
  // => dir: Kotlination/Kotlin/Practice | fileName: getFileNameExample | extension: kt
+
        // => dir: Kotlination/Kotlin/Practice | fileName: getFileNameExample | extension: kt
}
+
    }
  
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
==أنظر أيضًا==
+
==انظر أيضًا==
* صفحة الصنف <code>[[Kotlin/kotlin.text/MatchResult/Destructured/index|Destructured]]</code>.
+
* الخاصية <code>[[Kotlin/kotlin.text/MatchResult/groupValues|MatchResult.groupValues]]</code>: تمثل [[Kotlin/collection/List|قائمة]] بقيم المجموعة المفهرسة المتطابقة.
* الخاصية <code>[[Kotlin/kotlin.text/MatchResult/groups|MatchResult.groups]]</code>: تعيد الخاصية <code>groups</code>  كائنًا من النوع <code>[[Kotlin/kotlin.text/MatchGroupCollection/index|MatchGroupCollection]]</code> يضم مجموعة المُطابقات الموجودة في  [[Kotlin/kotlin.text/Regex/index|التعبير النمطي]]. حجم تلك المجموعة يساوي <code>groupCount + 1،</code> حيث<code>groupCount</code> هو عدد المجموعات المطابَقة في  <nowiki/>[[Kotlin/kotlin.text/Regex/index|التعبير النمطي]]. تلك المجموعات مُفهرسة من 1 حتى <code>groupCount،</code> والمجموعة ذات الفهرس <code>0</code> توافق المطابقة الكلية.
+
* الخاصية <code>[[Kotlin/kotlin.text/MatchResult/groups|MatchResult.groups]]</code>: تمثل [[Kotlin/collections|مجموعةً]] (collection) تضم جميع المجموعات (groups) المتطابقة باستعمال [[Kotlin/kotlin.text/Regex/index|تعبير نمطي]] محدد.
* الخاصية <code>[[Kotlin/kotlin.text/MatchResult/groupValues|MatchResult.groupValues]]</code>: تعيد  [[Kotlin/List|لائحة]] تضم مجموعة المُطابقات  <nowiki/>[[Kotlin/kotlin.text/Regex/index|للتعبير النمطي]]. حجم تلك [[Kotlin/List|اللائحة]] يساوي <code>groupCount + 1،</code> حيث<code>groupCount</code> هو عدد المجموعات المطابَقة في  <nowiki/>[[Kotlin/kotlin.text/Regex/index|التعبير النمطي]]. تلك المجموعات مُفهرسة من 1 حتى <code>groupCount،</code> والمجموعة ذات الفهرس <code>0</code> توافق المطابقة الكلية.
+
* <nowiki/><nowiki/>الخاصية <code>[[Kotlin/kotlin.text/MatchResult/range|MatchResult.range]]</code>: تمثل مجال الفهارس الذي يحدد مكان مُطابقة [[Kotlin/kotlin.text/Regex/index|تعبير نمطي]] محدد في السلسلة النصية الأصلية.
 +
* الخاصية <code>[[Kotlin/kotlin.text/MatchResult/value|MatchResult.value]]</code>: تمثل [[Kotlin/String|السلسلة النصية]] المُدخلة، أو جزءًا منها، والمُطابقة [[Kotlin/kotlin.text/Regex/index|للتعبير النمطي]]. 
  
 
==مصادر==
 
==مصادر==
* [http://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/-match-result/destructured.html الخاصية MatchResult.destructured في التوثيق الرسميّ للمكتبة القياسيّة في لغة Kotlin.]
+
* [http://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/-match-result/destructured.html صفحة الخاصية MatchResult.destructured في التوثيق الرسميّ للمكتبة القياسيّة في لغة Kotlin.]
 
[[تصنيف:Kotlin]]
 
[[تصنيف:Kotlin]]
 
[[تصنيف:Kotlin Property]]
 
[[تصنيف:Kotlin Property]]
 +
[[تصنيف:Kotlin Text]]
 +
[[تصنيف:Kotlin MatchResult]]

المراجعة الحالية بتاريخ 06:04، 30 أغسطس 2018

تمثل الخاصية MatchResult.destructured‎ نسخةً من الصنف Destructured توفّر مكونات عملية الإسناد بالتفكيك (destructuring assignment) التي تطبق على قيم المجموعة المُطابقة.

تطابق الدالة component1 قيمة المجموعة الأولى، وتطابق الدالة component2 قيمة المجموعة الثانية، وهلم جرًا.

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

open val destructured: Destructured

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

تعاد نسخةٌ من الصنف Destructured.

أمثلة

ينشِئ التابع Regex()‎ في الشيفرة التالية تعبيرًا نمطيًا باسم regex لتفكيك مسارات الملفات إلى ثلاث مُركّبات: المجلد (directory) واسم الملف (fileName) والامتداد (extension)، ثم نعرّف سلسلة نصية باسم fullPath تحتوي مسار أحد الملفات، ثم نستخرج من fullPath مجموعات النتائج عبر استدعاء الدالة matchEntire()‎ مع regex وتمرير fullPath إليها كوسيط. نستخدم بعدئذٍ الخاصية MatchResult.destructured لاستخراج مجموعات النتائج:

package com.kotlination.filename

fun main(args: Array<String>) {

    val fullPath = "Kotlination/Kotlin/Practice/getFileNameExample.kt"

    val regex = """(.+)/(.+)\.(.+)""".toRegex()
    val matchResult = regex.matchEntire(fullPath)

    if (matchResult != null) {
        val (directory, fileName, extension) = matchResult.destructured
        println("dir: $directory | fileName: $fileName | extension: $extension")
        // => dir: Kotlination/Kotlin/Practice | fileName: getFileNameExample | extension: kt
    }

}

انظر أيضًا

مصادر