走过海棠暮

文章 0 评论 0 浏览 24

走过海棠暮 2024-12-04 17:10:23

您可以使用“handheld”开关向移动设备提供不同的 CSS。

我建议研究用户代理检测,例如 PHP 类似于:

<? if (
 stristr($ua, "Windows CE") or
 stristr($ua, "AvantGo") or
 stristr($ua,"Mazingo") or
 stristr($ua, "Mobile") or
 stristr($ua, "T68") or
 stristr($ua,"Syncalot") or
 stristr($ua, "Blazer") ) {
 $DEVICE_TYPE="MOBILE";
 }
 if (isset($DEVICE_TYPE) and $DEVICE_TYPE=="MOBILE") {
 $location='mobile/index.php';
 header ('Location: '.$location);
 exit;
 }
 ?> 

You can serve different css to a mobile device by using the ="handheld" switch.

I suggest looking into User Agent Detection, such with PHP similar to:

<? if (
 stristr($ua, "Windows CE") or
 stristr($ua, "AvantGo") or
 stristr($ua,"Mazingo") or
 stristr($ua, "Mobile") or
 stristr($ua, "T68") or
 stristr($ua,"Syncalot") or
 stristr($ua, "Blazer") ) {
 $DEVICE_TYPE="MOBILE";
 }
 if (isset($DEVICE_TYPE) and $DEVICE_TYPE=="MOBILE") {
 $location='mobile/index.php';
 header ('Location: '.$location);
 exit;
 }
 ?> 

页面加载效果 - 每个新页面从不同的方向滑入(...作为使用scrollTo的单页网站)

走过海棠暮 2024-12-04 16:25:04

这是使用 ACCUMARRAY 的示例:

y = [1.3 1 1 1 2 2 2 2 1 1 3 3 4 5];

[g,~,gl] = grp2idx(y);
count = accumarray(g,1);
p = count(g) ./ numel(g)

概率:

>> [y(:) p]
ans =
          1.3     0.071429
            1      0.35714
            1      0.35714
            1      0.35714
            2      0.28571
            2      0.28571
            2      0.28571
            2      0.28571
            1      0.35714
            1      0.35714
            3      0.14286
            3      0.14286
            4     0.071429
            5     0.071429

您可以看到摘要出现次数为:

>> [gl count]
ans =
            1            5
          1.3            1
            2            4
            3            2
            4            1
            5            1

请注意,我正在使用 GRP2IDX处理诸如 1.3 或不从 1 开始的整数的情况。

Here is an example using ACCUMARRAY:

y = [1.3 1 1 1 2 2 2 2 1 1 3 3 4 5];

[g,~,gl] = grp2idx(y);
count = accumarray(g,1);
p = count(g) ./ numel(g)

The probabilities:

>> [y(:) p]
ans =
          1.3     0.071429
            1      0.35714
            1      0.35714
            1      0.35714
            2      0.28571
            2      0.28571
            2      0.28571
            2      0.28571
            1      0.35714
            1      0.35714
            3      0.14286
            3      0.14286
            4     0.071429
            5     0.071429

You can see a summary of occurrences as:

>> [gl count]
ans =
            1            5
          1.3            1
            2            4
            3            2
            4            1
            5            1

Note that I am using GRP2IDX to handle cases like 1.3 or integers not starting at 1.

Matlab - 计算向量中每个元素的概率

走过海棠暮 2024-12-04 16:06:03

您可以使用布尔运算符:

foreground = self.foreground or c4d.COLOR_TRANS

You can use the boolean operators:

foreground = self.foreground or c4d.COLOR_TRANS

对于这个三元条件有更好的解决方案吗?

走过海棠暮 2024-12-04 14:48:12

使用很脏吗? Db 列上的函数触发电子邮件

Using the is dirty? function on Db column to trigger the email

当column_name改变时如何触发观察者?

走过海棠暮 2024-12-04 12:41:16

这是我的 @Chriseyre2000 解决方案的稍微不同的版本,使用异步操作和 PartitionKey 查询。在我的例子中,它被设计为在辅助角色中连续运行。如果您有很多条目需要清理,这可能会更容易记忆。

static class LogHelper
{
    /// <summary>
    /// Periodically run a cleanup task for log data, asynchronously
    /// </summary>
    public static async void TruncateDiagnosticsAsync()
    {
        while ( true )
        {
            try
            {
                // Retrieve storage account from connection-string
                CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                    CloudConfigurationManager.GetSetting( "CloudStorageConnectionString" ) );

                CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

                CloudTable cloudTable = tableClient.GetTableReference( "WADLogsTable" );

                // keep a weeks worth of logs
                DateTime keepThreshold = DateTime.UtcNow.AddDays( -7 );

                // do this until we run out of items
                while ( true )
                {
                    TableQuery query = new TableQuery();
                    query.FilterString = string.Format( "PartitionKey lt '0{0}'", keepThreshold.Ticks );
                    var items = cloudTable.ExecuteQuery( query ).Take( 1000 );

                    if ( items.Count() == 0 )
                        break;

                    Dictionary<string, TableBatchOperation> batches = new Dictionary<string, TableBatchOperation>();
                    foreach ( var entity in items )
                    {
                        TableOperation tableOperation = TableOperation.Delete( entity );

                        // need a new batch?
                        if ( !batches.ContainsKey( entity.PartitionKey ) )
                            batches.Add( entity.PartitionKey, new TableBatchOperation() );

                        // can have only 100 per batch
                        if ( batches[entity.PartitionKey].Count < 100)
                            batches[entity.PartitionKey].Add( tableOperation );
                    }

                    // execute!
                    foreach ( var batch in batches.Values )
                        await cloudTable.ExecuteBatchAsync( batch );

                    Trace.TraceInformation( "WADLogsTable truncated: " + query.FilterString );
                }
            }
            catch ( Exception ex )
            {
                Trace.TraceError( "Truncate WADLogsTable exception {0}", ex.Message );
            }

            // run this once per day
            await Task.Delay( TimeSpan.FromDays( 1 ) );
        }
    }
}

要启动该流程,只需从辅助角色的 OnStart 方法中调用此方法即可。

// start the periodic cleanup
LogHelper.TruncateDiagnosticsAsync();

Here's my slightly different version of @Chriseyre2000's solution, using asynchronous operations and PartitionKey querying. It's designed to run continuously within a Worker Role in my case. This one may be a bit easier on memory if you have a lot of entries to clean up.

static class LogHelper
{
    /// <summary>
    /// Periodically run a cleanup task for log data, asynchronously
    /// </summary>
    public static async void TruncateDiagnosticsAsync()
    {
        while ( true )
        {
            try
            {
                // Retrieve storage account from connection-string
                CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                    CloudConfigurationManager.GetSetting( "CloudStorageConnectionString" ) );

                CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

                CloudTable cloudTable = tableClient.GetTableReference( "WADLogsTable" );

                // keep a weeks worth of logs
                DateTime keepThreshold = DateTime.UtcNow.AddDays( -7 );

                // do this until we run out of items
                while ( true )
                {
                    TableQuery query = new TableQuery();
                    query.FilterString = string.Format( "PartitionKey lt '0{0}'", keepThreshold.Ticks );
                    var items = cloudTable.ExecuteQuery( query ).Take( 1000 );

                    if ( items.Count() == 0 )
                        break;

                    Dictionary<string, TableBatchOperation> batches = new Dictionary<string, TableBatchOperation>();
                    foreach ( var entity in items )
                    {
                        TableOperation tableOperation = TableOperation.Delete( entity );

                        // need a new batch?
                        if ( !batches.ContainsKey( entity.PartitionKey ) )
                            batches.Add( entity.PartitionKey, new TableBatchOperation() );

                        // can have only 100 per batch
                        if ( batches[entity.PartitionKey].Count < 100)
                            batches[entity.PartitionKey].Add( tableOperation );
                    }

                    // execute!
                    foreach ( var batch in batches.Values )
                        await cloudTable.ExecuteBatchAsync( batch );

                    Trace.TraceInformation( "WADLogsTable truncated: " + query.FilterString );
                }
            }
            catch ( Exception ex )
            {
                Trace.TraceError( "Truncate WADLogsTable exception {0}", ex.Message );
            }

            // run this once per day
            await Task.Delay( TimeSpan.FromDays( 1 ) );
        }
    }
}

To start the process, just call this from the OnStart method in your worker role.

// start the periodic cleanup
LogHelper.TruncateDiagnosticsAsync();

Windows Azure - 清理 WADLogsTable

走过海棠暮 2024-12-04 09:45:40

不,这是不可能的。想象一下,如果这可能的话,事情将会多么疯狂。

如果您希望在 Child 情况下跳过某些特定内容,请考虑重新设计您的设计以更好地表示您需要的内容(例如,也许您还需要覆盖 Child 类中的其他内容)。或者,您可以在 Parent 类中提供另一个 Foo(),该类除了调用其 base.Foo() 之外不执行任何操作。

No, this isn't possible. Imagine how crazy things would be if this was possible.

If you want something specific skipped in the Child case, consider reworking your design to better represent what you need (e.g. maybe you need to override something else in the Child class, too). Or, you could provide another Foo() in the Parent class that doesn't do anything except call its base.Foo().

C#:有什么方法可以跳过多态性中的一个基调用吗?

走过海棠暮 2024-12-04 08:37:12

有时是的。当您使用静态导入时,您静态导入的类中的字段和方法可能“看起来”来自您的类。

恕我直言,这确实会影响可理解性。

也就是说,我在 JUnit 测试中一直使用它!

Sometimes yes. When you use a static import, the fields and methods from the class you statically imported might "look like" they come from your class.

This does impact understandability, IMHO.

That said, I use it all the time in JUnit tests!

java中静态导入的正确使用

走过海棠暮 2024-12-04 07:17:56

矩形二维数组的解决方案确实很简单,但我遇到了问题。我的二维数组由不同长度的一维数组组成:

$myArray = [
    [1, 2, 3, 4],
    [5, 6, 7],
    [8, 9]
];

我想出了更通用的解决方案将任何二维数组转换为一维:

function array2DTo1D($arr2D) {
    $i = 0; $j = 0;
    $arr1D = [];
    while (isset($arr2D[$i][0])) {
        while (isset($arr2D[$i][$j])) {
            $arr1D[] = $arr2D[$i][$j];
            $j++;
        }
        $i++; $j = 0;
    }
    return $arr1D;
}

The solution for rectangular 2D array is simple indeed, but I had a problem. My 2D-array consisted of 1D arrays of different lengths :

$myArray = [
    [1, 2, 3, 4],
    [5, 6, 7],
    [8, 9]
];

I came up with more generalized solution to turn any 2D array into 1D:

function array2DTo1D($arr2D) {
    $i = 0; $j = 0;
    $arr1D = [];
    while (isset($arr2D[$i][0])) {
        while (isset($arr2D[$i][$j])) {
            $arr1D[] = $arr2D[$i][$j];
            $j++;
        }
        $i++; $j = 0;
    }
    return $arr1D;
}

php中的二维多维数组到一维数组

走过海棠暮 2024-12-04 06:34:34

我建议通过添加自定义事件来解决此问题,因为您的标签暗示您可能会理解。

如果没有,请按照以下步骤操作。

1) 创建一个新的事件类型(在actionscript 中扩展事件类 - 确保覆盖clone())

2) 在弹出窗口的父应用程序中为新事件类型添加一个事件侦听器

3) 使弹出窗口分派您的新事件关闭之前的事件类型

4) 在事件处理程序中处理您要查找的任何内容(用户 ID?)。

我建议将 userID 附加到实际事件,这样父级就不会直接寻址 login.userID。从松耦合的角度来看,它更正确。也就是说,如果您不愿意,您可以通过不附加用户 ID 来简化解决方案。松耦合是一个伟大的目标,但如果您只打算使用这种关系一次,那么它并不是非常必要的。

如果您选择采用更紧密的耦合路线,那么您只需分派具有自定义“类型”的事件,而不是扩展事件。

如果您需要较低级别的示例(更少的描述,更多的代码),请告诉我,我也可以提供帮助。

下面提供的示例是稍微复杂的版本,您可以在其中扩展事件以包含数据。

事件类::

package mycomponents
{
    import flash.events.Event;
    public class CustomEvent extends Event
    {
        public static const EVENT_TYPE_NAME:String = "myEventType"

        public var mUserID:String = "";
        public var mSuccess:Boolean = false;

        public function CustomEvent(aType:String, aUserID:String, aSuccess:Boolean)
        {
            super(aType)
            mUserID = aUserID;
            mSuccess = aSuccess;
        }

        override public function clone():Event
        {
            var lEvent:CustomEvent = new CustomEvent(mUserID, mSuccess);
            return lEvent;
        }
    }
}

在 Popup::

private var loginSuccessful:Boolean = false;

private function onDataLoaded(e:Event):void{
    var xml:XML= new XML(e.target.data);
    if(xml.status=="success"){

        userID = username.text;
        loginSuccessful = true;             
        //SEND DATA TO MAIN APPLICATION
        dispatchEvent(new CustomEvent(CustomEvent.EVENT_TYPE_NAME, userID, loginSuccessful );
        PopUpManager.removePopUp(this);

    }else{
        fail.visible=true;
        username.text="";
        password.text="";
        username.setFocus();
    }           
}

protected function titlewindow1_removeHandler(event:FlexEvent):void
{          
    if (!loginSuccessful)
        dispatchEvent(new CustomEvent(CustomEvent.EVENT_TYPE_NAME," userID, loginSuccessful ));
} 

和主应用程序中::

import mycomponents.CustomEvent;

private function application1_creationCompleteHandler(event:FlexEvent):void 
{
    //...your code
    login.addEventListener(CustomEvent.EVENT_TYPE_NAME, handleLoginEvent);
}

private function handleLoginEvent(aEvent:CustomEvent)
{
    //My example code dispatches an event with mSuccess = false if the login prompt closes
    //without a successful login
    //
    //now do whatever you want with the information from the popup
    //aEvent.mUserID gets you ID
    //aEvent.mSuccess gets you success

}

在工作休息期间将其放在一起,因此没有 Promise 会按原样编译。

I would recommend solving this by adding a custom event, as your tag implies you may understand.

If not, here are the steps you would follow.

1) Create a new Event type (extend the Event class in actionscript - be sure to override clone())

2) Add an event listener for your new Event type in the parent application on the popup

3) cause the popup to dispatch your new Event type before it closes

4) Handle whatever it is you're looking for (userID?) in the event handler.

I would recommend attaching the userID to the actual event, so that the parent is not directly addressing login.userID. From a loose coupling standpoint, it's more correct. That said, if you don't wish to, you can simplify the solution by NOT attaching the userID. Loose coupling is a great goal, but if you only plan to use this relationship once, it's not incredibly necessary.

If you choose to go the tighter coupling route, then you only have to dispatch an event with a custom "type" instead of an extended Event.

If you need a lower level example (less description, more code) let me know, and I can help with that as well.

The example provided below is the slightly more complex version, where you extend an event to contain the data.

Event class::

package mycomponents
{
    import flash.events.Event;
    public class CustomEvent extends Event
    {
        public static const EVENT_TYPE_NAME:String = "myEventType"

        public var mUserID:String = "";
        public var mSuccess:Boolean = false;

        public function CustomEvent(aType:String, aUserID:String, aSuccess:Boolean)
        {
            super(aType)
            mUserID = aUserID;
            mSuccess = aSuccess;
        }

        override public function clone():Event
        {
            var lEvent:CustomEvent = new CustomEvent(mUserID, mSuccess);
            return lEvent;
        }
    }
}

In Popup::

private var loginSuccessful:Boolean = false;

private function onDataLoaded(e:Event):void{
    var xml:XML= new XML(e.target.data);
    if(xml.status=="success"){

        userID = username.text;
        loginSuccessful = true;             
        //SEND DATA TO MAIN APPLICATION
        dispatchEvent(new CustomEvent(CustomEvent.EVENT_TYPE_NAME, userID, loginSuccessful );
        PopUpManager.removePopUp(this);

    }else{
        fail.visible=true;
        username.text="";
        password.text="";
        username.setFocus();
    }           
}

protected function titlewindow1_removeHandler(event:FlexEvent):void
{          
    if (!loginSuccessful)
        dispatchEvent(new CustomEvent(CustomEvent.EVENT_TYPE_NAME," userID, loginSuccessful ));
} 

And in the Main Application::

import mycomponents.CustomEvent;

private function application1_creationCompleteHandler(event:FlexEvent):void 
{
    //...your code
    login.addEventListener(CustomEvent.EVENT_TYPE_NAME, handleLoginEvent);
}

private function handleLoginEvent(aEvent:CustomEvent)
{
    //My example code dispatches an event with mSuccess = false if the login prompt closes
    //without a successful login
    //
    //now do whatever you want with the information from the popup
    //aEvent.mUserID gets you ID
    //aEvent.mSuccess gets you success

}

Tossed that together in the middle of a break at work, so no promises will compile as-is.

将数据从弹出窗口发送到主应用程序。

走过海棠暮 2024-12-04 06:12:00

不要使用更改,而是尝试 .keyup() ,即使单击 ctrl v ,它也应该在 IE6 中工作,并覆盖您,即使焦点没有从输入上移开,那么您也可以使用 .focus() 覆盖右键单击+粘贴。

Instead of using change, try .keyup() , that should work in IE6 even when ctrl v is clicked and cover you even if focus isn't taken off the input, then you can also use .focus() to cover the Right Click + Paste.

.change 在 IE 中存在 bug

走过海棠暮 2024-12-04 05:13:58

您可以使用更改事件处理程序将此参数传递给您的侦听器(combo,newValue,oldValue)

you can use change event handler that pass this params to your listener ( combo, newValue, oldValue )

Extjs 组合框获取以前的值吗?

走过海棠暮 2024-12-04 05:07:56

使用 NSLog 尝试检查 UITableView 中的剖面视图标题何时被准确绘制。
也许你可以弄清楚为什么会发生这种情况。然后尝试使用scrollEnabled = NO,正如您所想的那样。

Using NSLog try to check when is your section view header from UITableView gets drawn exactly.
May be you can then figure out why this is happening. Then try using scrollEnabled=NO, as you are thinking.

UITableView 普通样式部分标题在搜索视图上重绘

走过海棠暮 2024-12-04 03:42:22

您的查询中需要解决方案表的目的是什么?从你的文字看来

mysql_query("SELECT COUNT(*) FROM offer offer WHERE offer.is_solved = 0  ORDER BY offer.creation_time  DESC LIMIT".$interval_begin.",".$interval_end);

就足够了。

“我们需要知道的是每个“提议”的解决方案的确切数量,而不仅仅是是否有任何解决方案。” - 在这种情况下,你最初的 SQL 是错误的,它只是计算订单。你需要类似的东西

mysql_query("SELECT offer.oid, COUNT(solution.oid) FROM offer offer LEFT JOIN ON offer.oid = solution.oid WHERE offer.is_solved = 0 GROUP BY offer.oid ORDER BY offer.creation_time  DESC LIMIT".$interval_begin.",".$interval_end);

What for do you need solution table in your query? From your text it looks like

mysql_query("SELECT COUNT(*) FROM offer offer WHERE offer.is_solved = 0  ORDER BY offer.creation_time  DESC LIMIT".$interval_begin.",".$interval_end);

would be enough.

"What we need to know is the exact number of solutions for each "offer", not just whether there is any solution at all." - In such case your initial SQL was wrong, it just counted orders. You need something like

mysql_query("SELECT offer.oid, COUNT(solution.oid) FROM offer offer LEFT JOIN ON offer.oid = solution.oid WHERE offer.is_solved = 0 GROUP BY offer.oid ORDER BY offer.creation_time  DESC LIMIT".$interval_begin.",".$interval_end);

mySQL 右外连接

走过海棠暮 2024-12-04 02:55:51

您应该使用 .live()

从文档中:

描述:将处理程序附加到所有元素的事件
匹配当前选择器,现在和将来。

You should use .live().

From the documentation:

Description: Attach a handler to the event for all elements which
match the current selector, now and in the future.

jquery 中没有触发事件,什么问题?

走过海棠暮 2024-12-04 00:02:32

什么 UTF 支持所有 Unicode 块?

所有 UTF 编码都支持所有 Unicode 块 - 没有不能表示任何 Unicode 代码点的 UTF 编码。但是,某些非 UTF、较旧的编码,例如 UCS-2(类似于 UTF-16,但缺少代理对,因此缺乏对 65535/U+FFFF 以上的代码点进行编码的能力)可能不会。

什么是最好的 UTF(性能、大小等),为什么?

对于主要是英语和/或只是 ASCII 的文本数据,UTF-8 是迄今为止最节省空间的。然而,UTF-8 有时比 UTF-16 和 UTF-32 的空间效率低,因为 UTF-16 和 UTF-32 所使用的大多数代码点都很高(例如大型 CJK 文本)。

这三种UTF有什么不同?

UTF-8 对每个 Unicode 代码点进行 1 到 4 个字节的编码。 Unicode 值 0 到 127 与 ASCII 中的值相同,其编码方式与 ASCII 中的值相同。值为 128 到 255 的字节用于多字节代码点。

UTF-16 以两个字节(一个 UTF-16 值)或四个字节(两个 UTF-16 值)对每个 Unicode 代码点进行编码。基本多语言平面中的任何内容(Unicode 代码点 0 到 65535,或 U+0000 到 U+FFFF)均使用一个 UTF-16 值进行编码。来自更高平原的代码点通过称为“代理对”的技术使用两个 UTF-16 值。

UTF-32 不是 Unicode 的可变长度编码;所有 Unicode 代码点值均按原样编码。这意味着 U+10FFFF 被编码为 0x0010FFFF

什么是字节顺序和字节顺序标记 (BOM)?

字节序是一段数据、特定 CPU 架构或协议对多字节数据类型的值进行排序的方式。 Little-endian 系统(例如 x86-32 和 x86-64 CPU)将最低有效字节放在前面,而 ​​big-endian 系统(例如 ARM、PowerPC 和许多网络协议)将最高有效字节放在前面。

在小端编码或系统中,32 位值0x12345678 被存储或传输为0x78 0x56 0x34 0x12。在大端编码或系统中,它被存储或传输为0x12 0x34 0x56 0x78

UTF-16 和 UTF-32 中使用字节顺序标记来表示文本将被解释为哪种字节序。 Unicode 以一种巧妙的方式做到了这一点——U+FEFF 是一个有效的代码点,用于字节顺序标记,而 U+FFFE 则不是。因此,如果文件以0xFF 0xFE开头,则可以假设文件的其余部分以小端字节顺序存储。

UTF-8 中的字节顺序标记在技术上是可行的,但由于明显的原因在字节序上下文中毫无意义。然而,以 UTF-8 编码的 BOM 开头的流几乎肯定意味着它是 UTF-8,因此可以用于识别。

UTF-8 的优点

  • ASCII 是 UTF-8 编码的子集,因此是将 ASCII 文本引入“Unicode 世界”的好方法,而无需进行数据转换
  • UTF-8 文本是ASCII 文本的最紧凑格式
  • 有效的 UTF-8 可以按字节值排序并生成排序的代码点

UTF-16 的优点

  • UTF-16 比 UTF-8 更容易解码,尽管它是一种可变长度编码
  • 对于 BMP 中的字符,UTF-16 比 UTF-8 更节省空间,但在 ASCII 之外

UTF-32

  • UTF-32 不是可变长度的,因此它不需要特殊的逻辑来解码

what UTF that are support all Unicode blocks ?

All UTF encodings support all Unicode blocks - there is no UTF encoding that can't represent any Unicode codepoint. However, some non-UTF, older encodings, such as UCS-2 (which is like UTF-16, but lacks surrogate pairs, and thus lacks the ability to encode codepoints above 65535/U+FFFF), may not.

What is the best UTF(performance, size, etc), and why ?

For textual data that is mostly English and/or just ASCII, UTF-8 is by far the most space-efficient. However, UTF-8 is sometimes less space-efficient than UTF-16 and UTF-32 where most of the codepoints used are high (such as large bodies of CJK text).

What is different between these three UTF ?

UTF-8 encodes each Unicode codepoint from one to four bytes. The Unicode values 0 to 127, which are the same as they are in ASCII, are encoded like they are in ASCII. Bytes with values 128 to 255 are used for multi-byte codepoints.

UTF-16 encodes each Unicode codepoint in either two bytes (one UTF-16 value) or four bytes (two UTF-16 values). Anything in the Basic Multilingual Plane (Unicode codepoints 0 to 65535, or U+0000 to U+FFFF) are encoded with one UTF-16 value. Codepoints from higher plains use two UTF-16 values, through a technique called 'surrogate pairs'.

UTF-32 is not a variable-length encoding for Unicode; all Unicode codepoint values are encoded as-is. This means that U+10FFFF is encoded as 0x0010FFFF.

what is endianness and byte order marks (BOM) ?

Endianness is how a piece of data, particular CPU architecture or protocol orders values of multi-byte data types. Little-endian systems (such as x86-32 and x86-64 CPUs) put the least-significant byte first, and big-endian systems (such as ARM, PowerPC and many networking protocols) put the most-significant byte first.

In a little-endian encoding or system, the 32-bit value 0x12345678 is stored or transmitted as 0x78 0x56 0x34 0x12. In a big-endian encoding or system, it is stored or transmitted as 0x12 0x34 0x56 0x78.

A byte order mark is used in UTF-16 and UTF-32 to signal which endianness the text is to be interpreted as. Unicode does this in a clever way -- U+FEFF is a valid codepoint, used for the byte order mark, while U+FFFE is not. Therefore, if a file starts with 0xFF 0xFE, it can be assumed that the rest of the file is stored in a little-endian byte ordering.

A byte order mark in UTF-8 is technically possible, but is meaningless in the context of endianness for obvious reasons. However, a stream that begins with the UTF-8 encoded BOM almost certainly implies that it is UTF-8, and thus can be used for identification because of this.

Benefits of UTF-8

  • ASCII is a subset of the UTF-8 encoding and therefore is a great way to introduce ASCII text into a 'Unicode world' without having to do data conversion
  • UTF-8 text is the most compact format for ASCII text
  • Valid UTF-8 can be sorted on byte values and result in sorted codepoints

Benefits of UTF-16

  • UTF-16 is easier than UTF-8 to decode, even though it is a variable-length encoding
  • UTF-16 is more space-efficient than UTF-8 for characters in the BMP, but outside ASCII

Benefits of UTF-32

  • UTF-32 is not variable-length, so it requires no special logic to decode

什么是最好的 UTF

更多

推荐作者

束缚m

文章 0 评论 0

alipaysp_VP2a8Q4rgx

文章 0 评论 0

α

文章 0 评论 0

一口甜

文章 0 评论 0

厌味

文章 0 评论 0

转身泪倾城

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文