$* and $@

$*:当用"$*"时,$*表示把所有参数作用一个字符串。

$@:当用"$@"时,$@表示把和每个参数作为一个单独的字符串。

#example:

#test.sh

#!/bin/bash

#---------------------------------------------

#This shell script test the difference between $* and $@

#---------------------------------------------
E_BADARGS=65

if [ ! -n "$1" ]
then
 echo "Usage:`basename $0` argument1 argument2 etc."
 exit $E_BADARGS
fi

echo

index=1

echo "Listing args with/"/$*/":"
for arg in "$*"
do
 echo "Arg #$index = $arg"
 echo "next line?"
 let "index+=1"
done

echo "Entire arg list seen as a single word"

index=1
echo "Listing args with /$*:"
for arg in $*
do
 echo "Arg #$index = $arg"
 let "indx+=1"
done
echo "Entire arg list seen as separate words"

index=1

echo "Listing args with /"/$@/":"
for arg in "$@"
do
 echo "Arg #$index = $arg"
 let "index+=1"
done
echo "Entire arg list seen as separate words"

index=1

echo "Listing args with /$@:"
for arg in $@
do
 echo "Arg #$index = $arg"
 let "index+=1"
done
echo "Entire arg list seen as separate words"

exit 0

 

$chmod +x test.sh

$./test.sh hello nice to meet you

the output is :


Listing args with"$*":
Arg #1 = hello nice to meet you
next line?
Entire arg list seen as a single word
Listing args with $*:
Arg #1 = hello
Arg #1 = nice
Arg #1 = to
Arg #1 = meet
Arg #1 = you
Entire arg list seen as separate words
Listing args with "$@":
Arg #1 = hello
Arg #2 = nice
Arg #3 = to
Arg #4 = meet
Arg #5 = you
Entire arg list seen as separate words
Listing args with $@:
Arg #1 = hello
Arg #2 = nice
Arg #3 = to
Arg #4 = meet
Arg #5 = you
Entire arg list seen as separate words

 

但有些时候$*and $@的输出会不一致,这取决于IFS的设置

for example:

#test2.sh

#!/bin/bash
set -- "First one" "second" "third:one" "" "Fifth: :one"
echo
echo "IFS unchanged, using $/$*"
c=0
for i in "$*" # quoted
do echo "$((c+=1)): [$i]" # This line remains the same in every instance.
# Echo args.
done
echo ---
echo 'IFS unchanged, using $*'
c=0
for i in $* # unquoted
do echo "$((c+=1)): [$i]"
done
echo ---
echo 'IFS unchanged, using "$@"'
c=0
for i in "$@"
do echo "$((c+=1)): [$i]"
done
echo ---
echo 'IFS unchanged, using $@'
c=0
for i in $@
do echo "$((c+=1)): [$i]"
done
echo ---
IFS=:
echo 'IFS=":", using "$*"'
c=0
for i in "$*"
do echo "$((c+=1)): [$i]"
done
echo ---
echo 'IFS=":", using $*'
c=0
for i in $*
do echo "$((c+=1)): [$i]"
done
echo ---
var=$*
echo 'IFS=":", using "$var" (var=$*)'
c=0
for i in "$var"
do echo "$((c+=1)): [$i]"
done
echo ---
echo 'IFS=":", using $var (var=$*)'
c=0
for i in $var
do echo "$((c+=1)): [$i]"
done
echo ---
var="$*"
echo 'IFS=":", using $var (var="$*")'
c=0
for i in $var
do echo "$((c+=1)): [$i]"
done
echo ---
echo 'IFS=":", using "$var" (var="$*")'
c=0
for i in "$var"
do echo "$((c+=1)): [$i]"
done
echo ---
echo 'IFS=":", using "$@"'
c=0
for i in "$@"
do echo "$((c+=1)): [$i]"
done
echo ---
echo 'IFS=":", using $@'
c=0
for i in $@
do echo "$((c+=1)): [$i]"
done
echo ---
var=$@
echo 'IFS=":", using $var (var=$@)'
c=0
for i in $var
do echo "$((c+=1)): [$i]"
done
echo ---
echo 'IFS=":", using "$var" (var=$@)'
c=0
for i in "$var"
do echo "$((c+=1)): [$i]"
done
echo ---
var="$@"
echo 'IFS=":", using "$var" (var="$@")'
c=0
for i in "$var"
do echo "$((c+=1)): [$i]"
done
echo ---
echo 'IFS=":", using $var (var="$@")'
c=0
for i in $var
do echo "$((c+=1)): [$i]"
done
echo
exit 0

 

The output as follows:


IFS unchanged, using "$*"
1: [First one second third:one  Fifth: :one]
---
IFS unchanged, using $*
1: [First]
2: [one]
3: [second]
4: [third:one]
5: [Fifth:]
6: [:one]
---
IFS unchanged, using "$@"
1: [First one]
2: [second]
3: [third:one]
4: []
5: [Fifth: :one]
---
IFS unchanged, using $@
1: [First]
2: [one]
3: [second]
4: [third:one]
5: [Fifth:]
6: [:one]
---
IFS=":", using "$*"
1: [First one:second:third:one::Fifth: :one]
---
IFS=":", using $*
1: [First one]
2: [second]
3: [third]
4: [one]
5: []
6: [Fifth]
7: [ ]
8: [one]
---
IFS=":", using "$var" (var=$*)
1: [First one:second:third:one::Fifth: :one]
---
IFS=":", using $var (var=$*)
1: [First one]
2: [second]
3: [third]
4: [one]
5: []
6: [Fifth]
7: [ ]
8: [one]
---
IFS=":", using $var (var="$*")
1: [First one]
2: [second]
3: [third]
4: [one]
5: []
6: [Fifth]
7: [ ]
8: [one]
---
IFS=":", using "$var" (var="$*")
1: [First one:second:third:one::Fifth: :one]
---
IFS=":", using "$@"
1: [First one]
2: [second]
3: [third:one]
4: []
5: [Fifth: :one]
---
IFS=":", using $@
1: [First one]
2: [second]
3: [third]
4: [one]
5: []
6: [Fifth]
7: [ ]
8: [one]
---
IFS=":", using $var (var=$@)
1: [First one second third one  Fifth   one]
---
IFS=":", using "$var" (var=$@)
1: [First one second third one  Fifth   one]
---
IFS=":", using "$var" (var="$@")
1: [First one second third:one  Fifth: :one]
---
IFS=":", using $var (var="$@")
1: [First one second third]
2: [one  Fifth]
3: [ ]
4: [one]

 

Pleasee taste it slowly!

                                                                摘自abs_guide_en

<?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Style; /** * Chart style. * * @since 0.12.0 */ class Chart extends AbstractStyle { /** * Width (in EMU). * * @var int */ private $width = 1000000; /** * Height (in EMU). * * @var int */ private $height = 1000000; /** * Is 3D; applies to pie, bar, line, area. * * @var bool */ private $is3d = false; /** * A list of colors to use in the chart. * * @var array */ private $colors = []; /** * Chart title. * * @var string */ private $title; /** * Chart legend visibility. * * @var bool */ private $showLegend = false; /** * Chart legend Position. * Possible values are 'r', 't', 'b', 'l', 'tr'. * * @var string */ private $legendPosition = 'r'; /** * A list of display options for data labels. * * @var array */ private $dataLabelOptions = [ 'showVal' => true, // value 'showCatName' => true, // category name 'showLegendKey' => false, //show the cart legend 'showSerName' => false, // series name 'showPercent' => false, 'showLeaderLines' => false, 'showBubbleSize' => false, ]; /** * A string that tells the writer where to write chart labels or to skip * "nextTo" - sets labels next to the axis (bar graphs on the left) (default) * "low" - labels on the left side of the graph * "high" - labels on the right side of the graph. * * @var string */ private $categoryLabelPosition = 'nextTo'; /** * A string that tells the writer where to write chart labels or to skip * "nextTo" - sets labels next to the axis (bar graphs on the bottom) (default) * "low" - labels are below the graph * "high" - labels above the graph. * * @var string */ private $valueLabelPosition = 'nextTo'; /** * @var string */ private $categoryAxisTitle; /** * @var string */ private $valueAxisTitle; /** * The position for major tick marks * Possible values are 'in', 'out', 'cross', 'none'. * * @var string */ private $majorTickMarkPos = 'none'; /** * Show labels for axis. * * @var bool */ private $showAxisLabels = false; /** * Show Gridlines for Y-Axis. * * @var bool */ private $gridY = false; /** * Show Gridlines for X-Axis. * * @var bool */ private $gridX = false; /** * Create a new instance. * * @param array $style */ public function __construct($style = []) { $this->setStyleByArray($style); } /** * Get width. * * @return int */ public function getWidth() { return $this->width; } /** * Set width. * * @param int $value * * @return self */ public function setWidth($value = null) { $this->width = $this->setIntVal($value, $this->width); return $this; } /** * Get height. * * @return int */ public function getHeight() { return $this->height; } /** * Set height. * * @param int $value * * @return self */ public function setHeight($value = null) { $this->height = $this->setIntVal($value, $this->height); return $this; } /** * Is 3D. * * @return bool */ public function is3d() { return $this->is3d; } /** * Set 3D. * * @param bool $value * * @return self */ public function set3d($value = true) { $this->is3d = $this->setBoolVal($value, $this->is3d); return $this; } /** * Get the list of colors to use in a chart. * * @return array */ public function getColors() { return $this->colors; } /** * Set the colors to use in a chart. * * @param array $value a list of colors to use in the chart * * @return self */ public function setColors($value = []) { $this->colors = $value; return $this; } /** * Get the chart title. * * @return string */ public function getTitle() { return $this->title; } /** * Set the chart title. * * @param string $value * * @return self */ public function setTitle($value = null) { $this->title = $value; return $this; } /** * Get chart legend visibility. * * @return bool */ public function isShowLegend() { return $this->showLegend; } /** * Set chart legend visibility. * * @param bool $value * * @return self */ public function setShowLegend($value = false) { $this->showLegend = $value; return $this; } /** * Get chart legend position. * * @return string */ public function getLegendPosition() { return $this->legendPosition; } /** * Set chart legend position. choices: * "r" - right of chart * "b" - bottom of chart * "t" - top of chart * "l" - left of chart * "tr" - top right of chart. * * default: right * * @param string $legendPosition * * @return self */ public function setLegendPosition($legendPosition = 'r') { $enum = ['r', 'b', 't', 'l', 'tr']; $this->legendPosition = $this->setEnumVal($legendPosition, $enum, $this->legendPosition); return $this; } /* * Show labels for axis * * @return bool */ public function showAxisLabels() { return $this->showAxisLabels; } /** * Set show Gridlines for Y-Axis. * * @param bool $value * * @return self */ public function setShowAxisLabels($value = true) { $this->showAxisLabels = $this->setBoolVal($value, $this->showAxisLabels); return $this; } /** * get the list of options for data labels. * * @return array */ public function getDataLabelOptions() { return $this->dataLabelOptions; } /** * Set values for data label options. * This will only change values for options defined in $this->dataLabelOptions, and cannot create new ones. * * @param array $values [description] */ public function setDataLabelOptions($values = []): void { foreach (array_keys($this->dataLabelOptions) as $option) { if (isset($values[$option])) { $this->dataLabelOptions[$option] = $this->setBoolVal( $values[$option], $this->dataLabelOptions[$option] ); } } } /* * Show Gridlines for Y-Axis * * @return bool */ public function showGridY() { return $this->gridY; } /** * Set show Gridlines for Y-Axis. * * @param bool $value * * @return self */ public function setShowGridY($value = true) { $this->gridY = $this->setBoolVal($value, $this->gridY); return $this; } /** * Get the categoryLabelPosition setting. * * @return string */ public function getCategoryLabelPosition() { return $this->categoryLabelPosition; } /** * Set the categoryLabelPosition setting * "none" - skips writing labels * "nextTo" - sets labels next to the (bar graphs on the left) * "low" - labels on the left side of the graph * "high" - labels on the right side of the graph. * * @param mixed $labelPosition * * @return self */ public function setCategoryLabelPosition($labelPosition) { $enum = ['nextTo', 'low', 'high']; $this->categoryLabelPosition = $this->setEnumVal($labelPosition, $enum, $this->categoryLabelPosition); return $this; } /** * Get the valueAxisLabelPosition setting. * * @return string */ public function getValueLabelPosition() { return $this->valueLabelPosition; } /** * Set the valueLabelPosition setting * "none" - skips writing labels * "nextTo" - sets labels next to the value * "low" - sets labels are below the graph * "high" - sets labels above the graph. * * @param string * @param mixed $labelPosition */ public function setValueLabelPosition($labelPosition) { $enum = ['nextTo', 'low', 'high']; $this->valueLabelPosition = $this->setEnumVal($labelPosition, $enum, $this->valueLabelPosition); return $this; } /** * Get the categoryAxisTitle. * * @return string */ public function getCategoryAxisTitle() { return $this->categoryAxisTitle; } /** * Set the title that appears on the category side of the chart. * * @param string $axisTitle */ public function setCategoryAxisTitle($axisTitle) { $this->categoryAxisTitle = $axisTitle; return $this; } /** * Get the valueAxisTitle. * * @return string */ public function getValueAxisTitle() { return $this->valueAxisTitle; } /** * Set the title that appears on the value side of the chart. * * @param string $axisTitle */ public function setValueAxisTitle($axisTitle) { $this->valueAxisTitle = $axisTitle; return $this; } public function getMajorTickPosition() { return $this->majorTickMarkPos; } /** * Set the position for major tick marks. * * @param string $position */ public function setMajorTickPosition($position): void { $enum = ['in', 'out', 'cross', 'none']; $this->majorTickMarkPos = $this->setEnumVal($position, $enum, $this->majorTickMarkPos); } /** * Show Gridlines for X-Axis. * * @return bool */ public function showGridX() { return $this->gridX; } /** * Set show Gridlines for X-Axis. * * @param bool $value * * @return self */ public function setShowGridX($value = true) { $this->gridX = $this->setBoolVal($value, $this->gridX); return $this; } } 你学习下,然后告诉我都是些什么方法
06-09
declare class Scroller { /** * constructor. * * @syscap SystemCapability.ArkUI.ArkUI.Full * @since 7 */ /** * constructor. * * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @since 10 */ /** * constructor. * * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @atomicservice * @since 11 */ constructor(); /** * Called when the setting slides to the specified position. * * @param { object } value * @syscap SystemCapability.ArkUI.ArkUI.Full * @since 7 */ /** * Called when the setting slides to the specified position. * * @param { object } value * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @since 10 */ /** * Called when the setting slides to the specified position. * * @param { object } value * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @atomicservice * @since 11 */ scrollTo(value: { /** * The X-axis offset. * * @type { number | string } * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @since 10 */ /** * The X-axis offset. * * @type { number | string } * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @atomicservice * @since 11 */ xOffset: number | string; /** * The Y-axis offset. * * @type { number | string } * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @since 10 */ /** * The Y-axis offset. * * @type { number | string } * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @atomicservice * @since 11 */ yOffset: number | string; /** * Descriptive animation. * * @type { ?({ duration?: number; curve?: Curve | ICurve } | boolean) } The object type provides custom animation parameters * and the boolean type enables default spring animation. * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @since 10 */ /** * Descriptive animation. * * @type { ?({ duration?: number; curve?: Curve | ICurve } | boolean) } The object type provides custom animation parameters * and the boolean type enables default spring animation. * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @atomicservice * @since 11 */ /** * Descriptive animation. * * @type { ?( ScrollAnimationOptions | boolean) } The ScrollAnimationOptions type provides custom animation parameters * and the boolean type enables default spring animation. * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @atomicservice * @since 12 */ animation?: ScrollAnimationOptions | boolean; });
03-26
<think>嗯,用户让我介绍一下这个Scroller类,特别是它的构造函数和scrollTo方法。看起来这是ArkUI的一部分,可能和HarmonyOS或OpenHarmony相关。首先,我需要理解这个类的用途。Scroller可能用于处理滚动相关的操作,比如在UI组件中滚动到某个位置。 用户提供的代码中有constructor和scrollTo方法的文档注释。注意到constructor有三个不同的注释块,分别对应不同的版本(since 7, 10, 11),并且有syscap、crossplatform、atomicservice这些标签。这说明Scroller类可能在不同版本中有不同的能力支持,特别是跨平台和原子服务。需要解释这些标签的含义,以及不同版本间的差异。 接下来看scrollTo方法,它接受一个对象参数,包含xOffset、yOffset和animation。每个参数都有类型说明和版本标签。xOffset和yOffset可以是number或string,这可能表示它们接受数值或百分比字符串。animation参数比较复杂,可以是对象或布尔值,用来定义动画效果,比如持续时间和曲线。 我需要确保在解释时覆盖以下几点: 1. Scroller类的作用和适用场景。 2. 构造函数在不同版本中的变化,特别是跨平台支持和原子服务相关的内容。 3. scrollTo方法的参数详细说明,包括每个属性的类型、用途,以及不同版本的支持情况。 4. 提到的系统能力(syscap)、跨平台(crossplatform)和原子服务(atomicservice)标签的意义,因为这些对开发者正确使用API很重要。 可能用户是刚开始接触这个类,或者需要确认如何正确使用scrollTo方法来实现滚动效果。需要结构清晰,分步骤解释,确保每个参数和版本差异都解释到位。还要注意代码示例是否有必要,但根据用户的问题,可能不需要具体示例,但需要明确参数的使用方法。 另外,注意用户提供的文档中存在重复的注释块,可能是因为不同版本有不同的修饰符,需要指出这些版本变化,比如从since 7到since 11的演变,以及跨平台支持的引入。同时,animation参数在since 12时类型名称从匿名对象变成了ScrollAnimationOptions,这可能是一个类型别名,需要说明。 最后,确保使用中文,避免术语错误,比如正确翻译“constructor”为“构造函数”,“parameters”为“参数”等。同时,按照系统级指令的要求,数学公式使用$...$,但在这个问题中可能不涉及数学表达式,所以主要关注代码块和文档注释的解析。</think>我将分步骤解析您提供的 `Scroller` 类声明: ### 一、类基本信息 $$Scroller$$ 是用于控制滚动行为的类,属于 ArkUI 框架的核心能力,通过 `SystemCapability.ArkUI.ArkUI.Full` 系统能力提供支持 ### 二、构造函数解析 ```typescript constructor() ``` 特性说明: 1. 版本演进: - 初始版本:**API 7** 开始支持 - 跨平台支持:**API 10** 新增 `@crossplatform` 标签 - 原子服务支持:**API 11** 新增 `@atomicservice` 标签 2. 能力要求: 需要系统具备 `SystemCapability.ArkUI.ArkUI.Full` 能力 ### 三、核心方法 scrollTo ```typescript scrollTo(value: { xOffset: number | string; yOffset: number | string; animation?: ScrollAnimationOptions | boolean; }) ``` #### 参数详解: 1. **xOffset** - 类型:`number | string` - 说明:X 轴滚动偏移量 - 支持版本: - 基础支持:API 10 - 原子服务支持:API 11 2. **yOffset** - 类型:`number | string` - 说明:Y 轴滚动偏移量 - 支持版本同 xOffset 3. **animation**(核心动画控制) - 类型:`ScrollAnimationOptions | boolean` - 功能说明: - **对象类型**:自定义动画参数 ```typescript { duration?: number; // 动画时长(单位:ms) curve?: Curve | ICurve // 动画曲线类型 } ``` - **布尔类型**: - `true`:启用默认弹簧动画 - `false`:无动画效果 - 版本演进: - API 10:支持对象/布尔类型 - API 11:增加原子服务支持 - API 12:类型重命名为 `ScrollAnimationOptions` ### 四、版本兼容策略 1. 跨平台开发时: - 使用 `@crossplatform` 标注的 API(API 10+) - 注意参数类型变化(如 API 12 的类型重命名) 2. 原子服务开发: - 需使用 `@atomicservice` 标注的 API(API 11+) - 需要对应版本的 SDK 支持 ### 五、典型使用场景 ```typescript // 创建滚动控制器 const scroller = new Scroller(); // 滚动到指定位置(带自定义动画) scroller.scrollTo({ xOffset: "100%", // 支持百分比字符串 yOffset: 200, animation: { duration: 500, curve: Curve.EaseInOut } }); // 快速滚动(使用默认动画) scroller.scrollTo({ xOffset: 0, yOffset: 0, animation: true }); ``` 需要特别注意不同 API 版本之间的参数类型兼容性,特别是在跨平台开发时建议使用最新稳定版 API。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值