String String::ToLower() const { String result; if (HasChars()) { result.Allocate(Length()); Algo::Range::Transform(Begin(), End(), result.MutableBegin(), Algo::Function::FunctorFromMemberRef(&Char::ToLower)); } return result; }
void String::Free() { if (HasChars()) { if (!(--m_buffer->m_refCounter)) { Mem::Delete(m_buffer->m_data, m_buffer->m_capacity); Mem::Delete(m_buffer); } m_begin = nullptr; m_length = 0; } }
String String::Concat(const String& str) const { String result; if (HasChars() || str.HasChars()) { result.Allocate(Length() + str.Length()); Iterator dest = Algo::Range::Copy(Begin(), End(), result.MutableBegin()); Algo::Range::Copy(str.Begin(), str.End(), dest); } return result; }
void read_and_execute() { char tempChar; while(HasChars()) { receive_char(&tempChar); data[current_pos] = tempChar; if(tempChar == '\r') { parse(); } current_pos++; } }
String String::Trim(bool left, bool right) const { if (HasChars()) { ConstIterator begin = Begin(), end = End(); while (left && begin != end && begin->IsWhiteSpace()) { ++begin; } while (right && end > begin && (end - 1)->IsWhiteSpace()) { --end; } if (end > begin) { return SubString(begin, end); } } return String(); }
// Take input from a computer and load it onto the cube buffer void rs232() { char tempval; int x = 0; int y = 0; int escape = 0; while (current_mode == MODE_BINARY) { // Switch state on red LED for debugging // Should switch state every time the code // is waiting for a byte to be received. debug_blink(LED_RED); // Wait until a byte has been received while(!HasChars()); // Load the received byte from rs232 into a buffer. receive_char(&tempval); // Uncommet this to echo data back to the computer // for debugging purposes. //SendChar(tempval); // Every time the cube receives a 0xff byte, // it goes into sync escape mode. // if a 0x00 byte is then received, the x and y counters // are reset to 0. This way the x and y counters are // always the same on the computer and in the cube. // To send an 0xff byte, you have to send it twice! // Go into sync escape mode if (tempval == 0xff) { // Wait for the next byte while(!HasChars()); // Get the next byte receive_char(&tempval); // Sync signal is received. // Reset x and y counters to 0. if (tempval == 0x00) { x = 0; y = 0; escape = 1; } // if no 0x00 byte is received, proceed with // the byte we just received. } if (escape == 0) { // Load data into the current position in the buffer fb[x][y] = tempval; // Check if we have reached the limits of the buffer array. if (y == 7) { if (x == 7) { // All data is loaded. Reset both counters y = 0; x = 0; // Copy the data onto the cube. tmp2cube(); } else { // A layer is loaded, reset y and increment x. x++; y = 0; } } else { // We are in the middle of loading a layer. increment y. y++; } } else { escape = 0; } } }