Example #1
0
inline String getSafePackFileName(const char* fileName){
    String str(fileName);
    //处理 双斜杠  
    //处理 '/'  to '\\'
    bool isInDirTag=false;
    long inserIndex=0;
    for (long i=0;i<(long)str.size();++i){
        char c=str[i];
        switch (c) {
            case '/':
            case '\\':
                if (!isInDirTag){
                    isInDirTag=true;
                    str[inserIndex]='\\';
                    ++inserIndex;
                }
                break;
            default:{
                isInDirTag=false;
                str[inserIndex]=lowerCaseChar(c);
                ++inserIndex;
            }
                break;
        }
    }
    str.resize(inserIndex);
    return str;
}
Example #2
0
// TODO: Handle the special case keys Print Screen and Pause.
KeyEvent readEvent() {
  const int ESCAPE_CODE = 0xE0;
  static bool nextScancodeIsEscaped = false;

  // Persistant storage for the state of the various modifier and toggle keys.
  static bool leftAlt      = false;
  static bool rightAlt     = false;
  static bool leftControl  = false;
  static bool rightControl = false;
  static bool leftShift    = false;
  static bool rightShift   = false;
  static bool leftSuper    = false;
  static bool rightSuper   = false;
  static bool capsLock     = false;
  static bool numLock      = false;
  static bool scrollLock   = false;

  u8 scancode = readScancode();

  if (scancode == ESCAPE_CODE) {
    nextScancodeIsEscaped = true;
    scancode = readScancode();
  }

  KeyEvent event;

  // If the seventh bit is set, the scancode represents a key release, otherwise
  // it's a key press.
  bool isPress = !(scancode & (1 << 7));
  event.action = isPress ? KeyEvent::DOWN : KeyEvent::UP;

  // Clear the seventh bit before indexing into the key code tables below.
  scancode &= ~(1 << 7);

  if (nextScancodeIsEscaped) {
    nextScancodeIsEscaped = false;
    event.key = ESCAPED_KEYS[scancode];
  } else {
    event.key = UNESCAPED_KEYS[scancode];
  }

  // Turn modifiers on or off based on whether this is a press or release.
  switch (event.key) {
    case Key::LEFT_ALT:      leftAlt      = isPress; break;
    case Key::RIGHT_ALT:     rightAlt     = isPress; break;
    case Key::LEFT_CONTROL:  leftControl  = isPress; break;
    case Key::RIGHT_CONTROL: rightControl = isPress; break;
    case Key::LEFT_SHIFT:    leftShift    = isPress; break;
    case Key::RIGHT_SHIFT:   rightShift   = isPress; break;
    case Key::LEFT_SUPER:    leftSuper    = isPress; break;
    case Key::RIGHT_SUPER:   rightSuper   = isPress; break;
    default: break;
  }

  // Switch the toggles if this is a key press, not a release.
  if (isPress) {
    switch (event.key) {
      case Key::CAPS_LOCK:   capsLock   = !capsLock;   break;
      case Key::NUM_LOCK:    numLock    = !numLock;    break;
      case Key::SCROLL_LOCK: scrollLock = !scrollLock; break;
      default: break;
    }
  }

  event.shift      = leftShift   || rightShift;
  event.control    = leftControl || rightControl;
  event.alt        = leftAlt     || rightAlt;
  event.super      = leftSuper   || rightSuper;
  event.capsLock   = capsLock;
  event.numLock    = numLock;
  event.scrollLock = scrollLock;

  if (isPress) {
    if (event.shift) {
      event.character = upperCaseChar(event.key);
    } else {
      event.character = lowerCaseChar(event.key);
    }
  } else {
    event.character = '\0';
  }

  return event;
}