nand2/07_Operating_System/07_String_Test/Readme.md.backup

54 lines
1.9 KiB
Plaintext
Raw Normal View History

2023-01-11 10:13:09 +00:00
## String.jack
Represents character strings. In addition for constructing and disposing strings, the class features methods for getting and setting individual characters of the string, for erasing the string's last character, for appending a character to the string's end, and more typical string-oriented operations.
### constructor String new(int maxLength)
constructs a new empty string with a maximum length of maxLength and initial length of 0.
### method void dispose()
Disposes this string.
### method int length()
Returns the current length of this string.
### method char charAt(int j)
Returns the character at the j-th location of this string.
### method String appendChar(char c)
Appends c to this string's end and returns this string.
### method void eraseLastChar()
Erases the last character from this string.
### method int intValue()
Returns the integer value of this string until a non-digit character is detected.
### method void setInt(int val)
Sets this string to hold a representation of the given value.
### function char newLine()
Returns the new line character.
### function char backSpace()
Returns the backspace character.
### function char doubleQuote()
Returns the double quote (`"`) character.
***
## Project
* Implement `String.jack` and at least the function `StdIO.printString(String s)`
* Test by running String_Test, which performs several String operation and outputs them to StdIO (UART)
**Hint:** Use the debug register to show which caracters are transmitted over UART_TX. Add the following code in function UART.writeChar():
```
do Memory.Poke(4107,data)
```
![](string.png)
* Run String_Test in real hardware on iCE40HX1K-EVB using a terminal program connected to UART.
* Compare your terminal output with:
```
new,appendChar: abcde
setInt: 12345
setInt: -32767
length: 5
charAt[2]: 99
setCharAt(2,'-'): ab-de
eraseLastChar: abcd
intValue: 456
intValue: -32123
backSpace: 129
doubleQuote: 34
newLine: 128
```