<commit_before>/*
 * Copyright 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.compose.foundation.text

import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.Placeholder

/** The annotation tag used by inline content. */
internal const val INLINE_CONTENT_TAG = "androidx.compose.foundation.text.inlineContent"
// A string that contains a replacement character specified by unicode. It's used as the default
// value of alternate text.
private const val REPLACEMENT_CHAR = "\uFFFD"
/**
 * Append an inline content into the AnnotatedString.
 * @param id The id of this inline content, it is referred by the [androidx.compose.foundation.text.CoreText]
 * parameter inlineContent to replace the [alternateText] to the corresponding composable.
 * @param alternateText The text to be replaced by the inline content. It's displayed when
 * the inlineContent parameter of [androidx.compose.foundation.text.CoreText] doesn't contain [id]. Accessibility
 * features will also use this text to describe the inline content.
 * @throws IllegalArgumentException if [alternateText] has zero length.
 */
fun AnnotatedString.Builder.appendInlineContent(
    id: String,
    alternateText: String = REPLACEMENT_CHAR
) {
    require(alternateText.isNotEmpty()) {
        "alternateText can't be an empty string."
    }
    pushStringAnnotation(INLINE_CONTENT_TAG, id)
    append(alternateText)
    pop()
}

/**
 * A data class that stores a composable to be inserted into the text layout.
 *
 * Different from a regular composable, a [Placeholder] is also needed for text layout to reserve
 * space. In this [placeholder], the size of the content and how it will be aligned within the
 * text line is defined. When the children composable is measured, its size given in
 * [Placeholder.width] and [Placeholder.height] will be converted into
 * [androidx.compose.ui.unit.Constraints] and passed through [androidx.compose.ui.Layout].
 *
 * @sample androidx.compose.foundation.samples.InlineTextContentSample
 * @see CoreText
 * @see Placeholder
 */
@Immutable
class InlineTextContent(<commit_msg>Address API review for AnnotatedString.Builder.appendInlineContent<commit_after>/*
 * Copyright 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.compose.foundation.text

import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.Placeholder

/** The annotation tag used by inline content. */
internal const val INLINE_CONTENT_TAG = "androidx.compose.foundation.text.inlineContent"
// A string that contains a replacement character specified by unicode. It's used as the default
// value of alternate text.
private const val REPLACEMENT_CHAR = "\uFFFD"
/**
 * Used to insert composables into the text layout. This method can be used together with the
 * inlineContent parameter of [BasicText]. It will append the [alternateText] to this
 * [AnnotatedString] and also mark this range of text to be replaced by a composable.
 * [BasicText] will try to find an [InlineTextContent] in the map defined by inlineContent whose
 * key equals to [id], and it will use the [InlineTextContent.children] to replace this range of
 * text.
 *
 * @sample androidx.compose.foundation.samples.InlineTextContentSample
 * @see InlineTextContent
 * @see BasicText
 *
 * @param id The id used to look up the [InlineTextContent], it is referred by the inlineContent
 * parameter of [BasicText] to replace the [alternateText] to the corresponding composable.
 * @param alternateText The text to be replaced by the inline content. It's displayed when
 * the inlineContent parameter of [BasicText] doesn't contain [id].
 * Accessibility features will also use this text to describe the inline content.
 * @throws IllegalArgumentException if [alternateText] has zero length.
 */
fun AnnotatedString.Builder.appendInlineContent(
    id: String,
    alternateText: String = REPLACEMENT_CHAR
) {
    require(alternateText.isNotEmpty()) {
        "alternateText can't be an empty string."
    }
    pushStringAnnotation(INLINE_CONTENT_TAG, id)
    append(alternateText)
    pop()
}

/**
 * A data class that stores a composable to be inserted into the text layout.
 *
 * Different from a regular composable, a [Placeholder] is also needed for text layout to reserve
 * space. In this [placeholder], the size of the content and how it will be aligned within the
 * text line is defined. When the children composable is measured, its size given in
 * [Placeholder.width] and [Placeholder.height] will be converted into
 * [androidx.compose.ui.unit.Constraints] and passed through [androidx.compose.ui.layout.Layout].
 *
 * @sample androidx.compose.foundation.samples.InlineTextContentSample
 * @see BasicText
 * @see Placeholder
 */
@Immutable
class InlineTextContent(
{'fraction_non_alphanumeric': 0.07400692269655514, 'fraction_numerical': 0.00263721773528927, 'mean_word_length': 4.384205856255545, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5634051', 'n_tokens_mistral': 1609, 'n_tokens_neox': 1593, 'n_words': 682}