EncoderFallbackBuffer 類別

定義

提供緩衝區,允許後援處理常式在無法編碼輸入字元時,將替代字串傳回至編碼器。Provides a buffer that allows a fallback handler to return an alternate string to an encoder when it cannot encode an input character.

public ref class EncoderFallbackBuffer abstract
public abstract class EncoderFallbackBuffer
type EncoderFallbackBuffer = class
Public MustInherit Class EncoderFallbackBuffer
繼承
EncoderFallbackBuffer
衍生

備註

編碼定義 Unicode 字元與編碼的位元組序列之間的對應。An encoding defines a mapping between a Unicode character and an encoded sequence of bytes. 如果未針對特定字元定義對應,則將輸入字元轉換成輸出位元組序列的編碼作業會失敗。An encoding operation, which converts an input character to an output byte sequence, fails if no mapping is defined for a particular character.

如果無法執行轉換,.NET Framework 會提供失敗處理機制(稱為 fallback)。The .NET Framework provides a failure handling mechanism, called a fallback, if a conversion cannot be performed. 所有編碼器回溯處理常式都必須執行下列動作:All encoder fallback handlers must implement the following:

  • 編碼器回復,由衍生自類別的類別表示 EncoderFallbackAn encoder fallback, which is represented by a class derived from the EncoderFallback class.

  • 編碼器回溯緩衝區,它是由衍生自類別的型別所表示 EncoderFallbackBuffer ,可將字串傳回轉換作業。An encoder fallback buffer, which is represented by a type derived from the EncoderFallbackBuffer class that can return a string to the conversion operation.

回退可以使用三個策略來處理轉換失敗:Fallbacks can use three strategies to handle conversion failures:

執行中的緩衝區 EncoderFallbackBuffer 代表要傳回編碼器以回應編碼器回復的整個字串。The buffer in an EncoderFallbackBuffer implementation represents the entire string to be returned to the encoder in response to an encoder fallback. 一般而言,實值也包含狀態資訊,例如要傳回編碼器的下一個字元的索引,以及要傳回的剩餘字元數。Generally, implementations also include state information, such as the index of the next character to return to the encoder and the number of remaining characters to be returned. 由於 EncoderFallbackBuffer 是抽象類別,因此它需要衍生類別至少執行下列成員:Because EncoderFallbackBuffer is an abstract class, it requires derived classes to implement the following members at a minimum:

  • Fallback 無法編碼字元時,編碼器所呼叫的多載方法。The overloaded Fallback method, which is called by the encoder when it cannot encode a character. 編碼器會將兩項資訊傳遞給回溯緩衝區執行:無法編碼的字元或代理組,以及輸入中的字元索引。The encoder passes two pieces of information to the fallback buffer implementation: the character or surrogate pair that could not be encoded and the index of the character in the input. 在編碼器回溯例外狀況處理常式中,會在此方法中擲回例外狀況。In an encoder fallback exception handler, the exception is thrown in this method. 否則,如果方法提供回復,則會傳回 true ,否則 false 會傳回。Otherwise, the method returns true if it provides a fallback, or false if it does not.

  • GetNextChar當方法傳回時,編碼器會重複呼叫的方法 Fallback trueThe GetNextChar method, which is called repeatedly by the encoder if the Fallback method returns true. 在後續呼叫中,處理常式應該會傳回其緩衝區中的每個字元。In successive calls, the handler should return each character in its buffer. 當它傳回所有字元時,它應該會傳回 U + 0000。When it has returned all characters, it should return U+0000. 例外狀況處理常式一律會傳回 U + 0000。An exception handler always returns U+0000.

  • MovePrevious方法,這個方法會嘗試將指標移至緩衝區中的上一個位置,並指出移動是否成功。The MovePrevious method, which tries to move the pointer to the previous position in the buffer and indicates whether the move was successful. 例外狀況處理常式一律會傳回 falseAn exception handler always returns false.

  • Remaining屬性,表示要傳回給編碼器的剩餘字元數。The Remaining property, which indicates the number of remaining characters to be returned to the encoder. 例外狀況回退處理常式一律會傳回零。An exception fallback handler always returns zero.

建構函式

EncoderFallbackBuffer()

初始化 EncoderFallbackBuffer 類別的新執行個體。Initializes a new instance of the EncoderFallbackBuffer class.

屬性

Remaining

在衍生類別中覆寫時,於目前的 EncoderFallbackBuffer 物件中取得仍要處理的字元數。When overridden in a derived class, gets the number of characters in the current EncoderFallbackBuffer object that remain to be processed.

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
Fallback(Char, Char, Int32)

在衍生類別中覆寫時,預備後援緩衝區來處理指定的 Surrogate 字組。When overridden in a derived class, prepares the fallback buffer to handle the specified surrogate pair.

Fallback(Char, Int32)

在衍生類別中覆寫時,預備後援緩衝區來處理指定的輸入字元。When overridden in a derived class, prepares the fallback buffer to handle the specified input character.

GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetNextChar()

在衍生類別中覆寫時,擷取後援緩衝區中的下一個字元。When overridden in a derived class, retrieves the next character in the fallback buffer.

GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
MovePrevious()

在衍生類別中覆寫時,會使 GetNextChar() 方法的下一個呼叫存取在目前字元位置之前的資料緩衝區字元位置。When overridden in a derived class, causes the next call to the GetNextChar() method to access the data buffer character position that is prior to the current character position.

Reset()

初始化與後援緩衝區有關的所有資料和狀態資訊。Initializes all data and state information pertaining to this fallback buffer.

ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

適用於

另請參閱